javadocs wrote:Two overloaded versions of sleep are provided: one that specifies the sleep time to the millisecond and one that specifies the sleep time to the nanosecond. However, these sleep times are not guaranteed to be precise, because they are limited by the facilities provided by the underlying OS.
...
In any case, you cannot assume that invoking sleep will suspend the thread for precisely the time period specified.
salvin francis wrote:If your core intention is gaming, I would suggest looking at gaming engines instead of java. A gaming engine takes care of the game loop/graphics/physics etc.. for you. You would have to do all that from scratch in java.
Having said that, yes, javaFx (or even swing) can be used to create basic 2d games.
Zachary Griggs wrote:Hi, welcome to the Ranch.
Game programming is quite complex and I'm by no means an expert, though I have programmed games in my free time. Here's a high-level overview:
What I'd recommend is using JavaFX as a base, with a Canvas to display the game screen. Create a simple GameObject which can render itself on a Canvas (retrieve the GraphicsContext2D and drawImage), and a List of GameObjects which belong to the game. You can use a JavaFX based timer which asks each GameObject to render itself and then advances the game by a frame (which can mean, for example, moving an object if the player is holding an arrow key). You can add event handlers to the game canvas to detect when the user does something like press the right/left key, and then propagate that message to all game objects. If you do something like this, you'll be able to create a simple Java-based game and you can make it more complex from there - for example JSON definition files for maps, switching between sprites to make animations, etc. For importing sprites, find some freeware ones online and add them to your Resources folder. Retrieve the resource as a Stream, and then pass that to the drawImage method on GraphicsContext2D.
Though really the most important thing is to just try it out yourself. Break apart what you want to do into simple tasks, and set some realistic goals. For example when I started making a game, my tasks were like this:
1) Make a JavaFX project
2) Add a game canvas to the project
3) Import a freeware sprite into the game
4) Render a sprite on the game window
5) Detect key presses on the canvas
6) Make the arrow keys move the player character
7) Add gravity to the player character
8) Add tiles to the game
.. and just build from there.
Mjm Chi wrote:Thank you! But if I understand clear, JavaFX is not a game engine, it is rather user interface library?
| Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |