Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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
  }


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: