I am currently working on a small js / canvas game called "tunnel 2" (I'm sure there is a famous summer version of this there, but I don't know anything). You can try the game here . Also, I would recommend chrome.
So, I developed chrome on google, and it works fine even on my crappy old machine. I will bypass ~ 30 frames per second. on my colleague the laptop gives> 100 frames per second. So far, so good. safari seems to work well too.
Next, I tried this on firefox 4 beta 10 ... and I only get ~ 10 frames per second. but right ff4 is not so slow, right?
I started to research. here is my main loop:
this.run = function () {
this.draw();
var
t = this,
timeLastTurn,
timeThisTurn = (new Date()).getTime()-1;
var loop = function () {
timeLastTurn = timeThisTurn;
timeThisTurn = (new Date()).getTime();
var dt = timeThisTurn - timeLastTurn;
t.turn(dt);
var res = t.draw();
if (!res.collision)
t.setState(2);
if (gameState == 1)
timer = window.setTimeout(loop, 5);
debug = dt;
}
loop();
}
what i noticed:
, this.draw(); , ( 5, ), ... firefox. s > 100 10 ! loop() , firefox 10 !
, dt. time-loop() - + 5 - ( - ).
ff4 180 , 170 5 ! , ~ 800 (gc, ), 180 .
- , ?
? , , , , 150 !? , , . ? - gc ( 0,10%), Firebug .
: (~ 5 ) firebug.
. info: setInterval setTimeout .