I've been into javascript game programming with html5 and canvas lately. So far I've only been able to implement a game loop with setInterval, but I'm aware this means using fixed timestep. I've always used game engines with the "delta time" approach, I'm sorry I can't recall how that timestep was called. But anyway, I had several questions.

  • How could I implement a game loop with the delta time approach?

  • Will I get benefit from it in any particular way?

Also any information you point out related to that is welcome.

  • \$\begingroup\$ This doesn't answer the question but for you it might be easier to find a javascript HTML5 engine where this is all taken care of. \$\endgroup\$ Apr 10, 2014 at 6:42
  • \$\begingroup\$ Well as I'm not doing this professionally but for the purpose of learning how to do it, I'm still interested. Although it's a nice advice, I'll take a look to some of those engines too \$\endgroup\$
    – Setzer22
    Apr 10, 2014 at 7:17
  • \$\begingroup\$ Reading other people's source code can be an excellent way to learn things. \$\endgroup\$
    – Thomas
    Apr 10, 2014 at 7:57

1 Answer 1


Basically you have three ways to periodically invoke some code.

  • have a infinite loop with sleeps.
  • use setIntervall to perodically be waken
  • use requestAnimationFrame for when the browser is idle

Although this is about animation, it covers the basic crux of the problem: Animating In Code Using JavaScript


You must log in to answer this question.

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