News for hackers. Stuff that matters.
Re:Game Timers: Issues and Solutions (2012) by iamevn on Wednesday August 18, 2021 @01:11AM (#28217962)
on my simple games I essentially do this which seems to work but I have concerns about it cascading out of control if a frame takes too long. any tips for dealing with that? so far I just aggressively profile to make sure my game logic has a good time buffer before it hits my timestep.

  const TIMESTEP = 1/60;
  let since_last_frame = 0.0;
  
  function update(dt) {
    since_last_frame += dt;
    while (since_last_frame > TIMESTEP) {
      tick();
      since_last_frame -= TIMESTEP;
    }
  }
  
  function tick() {
    // handle game logic at a fixed timestep
  }

There are no comments on this comment yet.