If java3d's timer is deprecated, what should be used in it's place?

I’m finding it amazingly difficult to start java game dev. Every book has a different idea of optimum and I can’t figure out which book I should follow.

Advice?

System.nanoTime() or System.currentTimeMillis() have been vastly improved from the errors and problems most likely presented in the books you’ve read. Especially for starting, they are the best. If you’re using LWJGL, they have a good timer as well, but if you can’t start java game dev then LWJGL is not something you should look into yet (but remember that it exists for when you get more comfortable programming).

Thanks for your response. Can you give me an example animation loop using either of these?

I think it depends on what you kind of games you want to create? Do you want 2D or 3D? Hardware accelerated or not? Puzzle or action? Network?

Each of the above decision will affect how you create your game. For example, if you want a simple 2D applet game, you will want to use the swing Canvas class and use the Graphics class to draw and paint stuff on screen. If you want OpenGL hardware accelerated games, you’ll want to look at OpenGL bindings like LWJGL or JOGL. If you want hardware accelerated but don’t want to deal with low-level OpenGL calls, you’ll want to look at game engines such as Slick (for 2D), and JavaMonkeyEngine or JPCT (for 3D).

There are so many choices that it is very easy to get confused when you are just learning the basics of game programming. Since I teach java programming and I have an interest in 3D accelerated games, I have created my own framework specifically to make it easy to learn the ins and outs of programming concepts in a gaming context. You can find the tutorials at http://env3d.org. The lessons are very easy to follow especially if you are a professional Java programmer.

Good luck and have lots of fun!

I’d like to develop 2d sidescrollers, puzzle games, 2d tactics games.

Here is the simplest loop. Perhaps not the greatest, but will be sufficient for early games:


public static final int FRAMERATE = 30;

public static void main(String[] args) throws InterruptedException {
   long millisDelay = 1000 / FRAMERATE;

   // ... setup game here

   while(!quitRequested) {
      long now = System.currentTimeMillis();
      // ... run game logic every frame

      long remaining = millisDelay - (System.currentTimeMillis() - now);
      if (remaining > 0)
         Thread.sleep(remaining);
   }

   // ... clean up game here
}

But I haven’t tested it and I’ve written just I as I woke up so please experiment with it and feel free to change it if you need to make something better.