Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


boolean onLoop( Game game, GameState state, GameInput input, Graphics2D gr ) {
  long nanosElapsed = state.tick();
  updateTime += nanosElapsed;
  int updateCount = 0;
  while (updateTime >= updateRate && updateCount < maxUpdates) {
    game.input( input );
    if (!game.isPlaying()) {
      return false;
    game.update( state );
    if (!game.isPlaying()) {
      return false;
    updateTime -= updateRate;
  drawTime += nanosElapsed;
  int drawCount = 0;
  if (drawTime >= drawRate || updateCount > 0) {
    state.interpolate = getStateInterpolation();
    state.forward = state.interpolate * state.seconds;
    state.backward = state.forward - state.seconds;
    game.draw( state, gr );
    drawTime -= (drawRate == 0 ? drawTime : drawRate);
  if (sleep && drawCount == 0 && updateCount == 0) {
    long actualTime = updateTime + state.getElapsedSinceTick();
    long sleep = (updateRate - actualTime) / 1000000L;
    if (sleep > 1) {
      try {
        Thread.sleep( sleep - 1 );
      } catch (Exception e) { }
  return (drawCount > 0);

I am a beginner in game programming. I wanted to know when using fixed time step why do we have different update rates and draw rates. I have seen this in more than just the above code and if i plan to make a 30 fps game then what is a reasonable draw rate to have to match 30 fps update rate?. Can you explain in understandable terms? I appreciate your help.

share|improve this question
Optimization and consistency – Raxvan Nov 26 '13 at 17:47
The article you linked explains everything very clearly, perhaps you should reread that, or ask for clarification on what part you don't understand. – AttackingHobo Nov 26 '13 at 17:57

The short version is that there can be a huge variation in frame rate due to a myriad of factors, many outside of the game's control. These variations can cause a lot of bugs and other gameplay oddities, especially in physics. Using a fixed timestep for updates avoids bugs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.