[web] JavaScript game loop

Started by
16 comments, last by ucm 12 years, 4 months ago

Here is my updated game loop for html5 canvas. It works well for both 'fast' and 'slow' computers...


// setInterval(GameLoop, 1);


var old_time = Date.now();
var FPS = 1/60;
function GameLoop(){
var new_time = Date.now();
var dt = ((new_time - old_time)/1000);
while(dt > FPS){
Update(FPS);
dt -= FPS;
}
Update(dt);
Render();
old_time = new_time;
}


Let me know if you find any 'issues' with this :) I have been working on it for a couple days now, and like the results.




Awesome BUnzaga!

Now lets see more man ;-)

This topic is closed to new replies.

Advertisement