Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  congusbongus Apr 10 at 6:42
    
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 –  Setzer22 Apr 10 at 7:17
    
Reading other people's source code can be an excellent way to learn things. –  Thomas Apr 10 at 7:57

1 Answer 1

up vote 3 down vote accepted

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

share|improve this answer
    
Thanks, that helped! –  Setzer22 Apr 11 at 9:21

Your Answer

 
discard

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.