2D Timing Mechanism

I’ve seen a lot of tutorials on how to do 2D games. I’ve done a couple myself, but really haven’t dug into it since Java 1.4 was in beta. Back then, the easiest thing to do to control a smooth framerate was a hack that involved an auto-adjusting thread that would sleep 1ms and “tick” every X milliseconds (where was 1000/frame rate).

If I was to start creating a 2D game with the core libraries, what would be the “latest and greatest” strategy to maintain a frame rate and draw to the screen? BufferStrategy and fullscreen? Another sleep/notify thread? I’ve seen a few, but I’m looking for the best to start with (and possibly an example) with the 1.6 library.

Thanks for any guidance or links you can propose!

Michael

There is a really good overview here
Killer Game Programming in Java

That’s exactly what I was looking for. It appears it hasn’t changed much. With Java 1.5+ is System.nanoTime a better choice for timer resolution than System.currentTimeMillis? Or does currentTimeMillis try to use the highest resolution timer available in more modern VMs?

Michael

Some people use nanoTime but in my opinion it’s really not important to get that type of resolution in a 2D Java game.

Yeah, it appears that Windows 98 is the one with timing issues and I really don’t care much about supporting it.

Michael

Windows 2K/XP has also problems, they have granulity of 10-15ms, which is pretty big for animation purposes. Windows 98 had something like 55ms which was very awful. Other platforms (mac, lin) have 1ms granulity as one would expect.

The nanosecond timer has other problems. The timing may be affected by energy saving features. Some older AMD dual core CPUs send different times from each core.

It doesn’t seem to work as well for me. I believe there’s some kind of “nanosecond timer is evil” topic on this forum somewhere that contains several posts from people who don’t like it.

I’ve made games that updated every 50ms and it looked fine. That obviously means an fps of 20.