My question is related with Fixed time step vs Variable time step. But where a fixed frame-rate improve the consistency of a physics based game, is it the case for a rythm game, or wouldn't it be preferable to use a variable frame-rate ?

Say, I set the frame-rate to 100/sec, that will lead to an accuracy of 10ms, which is correct, but depending on the computer it will be possible to have a better accuracy. And if I set a too high frame-rate, some other computers may not follow, which may resolve in unsyncing the game and the music.

  • The first solution that came in my mind is to use a variable frame-rate. This way, the game will not be unsynchronized with the music, but the accuracy is too dependent of the computer.
  • Another, better, idea (I don't know if this is possible or not), would be to get the instant when has been pressed a key, and the accuracy will be no more dependent of the frame-rate. I'll make this game with LWJGL and I while reading the javadoc I found the method getEventNanoseconds(), and I was wondering how it is reliable since it's written "Only useful for relative comparisons with other Keyboard events, as the absolute time has no defined origin.".

What game loop method, do you think, is the most appropriate for a rythm game ? And for a rythm game with keysound ? Did you made a rythm game, or some game that require a good accuracy and how did you manage the updating ?

Thanks for your help ! :)


2 Answers 2


1) What Kimau said about compensating for controller lag/perceptional differences is important. While a lot of people get the basic rhythm, just translating it into a keypress might mean they're slightly off. If you can, give them exact feedback where their press occurred. (I.e. display a marker relative to the real beat, or something similar)

2) relative comparisons with other keyboard events are good - if you use a keyboard event to start play. Otherwise, you need to use system clock for the initial event, and then slowly transition over to keyboard events. Check out the NTP (RFC 1305) for issues in synchronizing different clocks with different resolutions

3) If you can, keep the controller on a different thread decoupled from the UI thread - that allows you a higher frequency there. (Assuming you don't use the timestamp on the keyboard events).

4) Having even a 100Hz resolution on keyboard event is small. Assuming a song with 120BPM, that's 2 beats per second. Which basically means your resolution is big enough that up to 2% time difference between real beat and your controller input are completely unnoticed. So, if you can, up the resolution

5) Also, if your sound driver allows you to query the current sample position, that would be the best timing indicator, since it's directly tied to the music.

And finally, DO have a musician check your idea of timing. There are plenty of rhythm games that are slightly off. Which is annoying as heck if you actually play music yourself.

  • \$\begingroup\$ Thanks for this answer. I didn't think of checking the current sample position but this is an excellent idea as it will not shift during pauses. Also LWJGL seems to already have its own events thread (the events received during a sleep are received in the correct order and with a 1ms precision) and their time are relative to the main timer. So it will simplify my job a lot :). I'm a musician myself and I totally agree that offbeat rhythm game are not fun, that's why I want to be the more synchronized as possible and asked this question. :) \$\endgroup\$
    – Mr_Qqn
    Commented Aug 19, 2010 at 20:18

It's highly dependent on the system you are using and how good the sound drivers or libraries are. Different consoles have vastly different approaches to sound streaming.

I would generally recommend a fixed time step for consistency because a smooth frame rate without pikes and dips is very important to keep a smooth feeling which doesn't break the flow.

Controller lag is a bigger factor than you would think. I quite like Rhythm games which use an auto-configure mode which basically lets the play define where they see the moment as being, then artificially compensating for it.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .