I'm making a simple game and I'm having a problem where after minimizing the window for a few seconds, upon return the game runs at twice the framerate, and even more after that, adding 60 each time. My game loop looks like this:

function disp(){
update();
draw();
requestAnimationFrame(disp);
}
requestAnimationFrame(disp);

With both update and draw not including requestAnimationFrame. I have tried this on both firefox and chrome with the same results. Any ideas why this is happening? I've used this same method tons of times and this is the first time this has ever happened.

EDIT: You can find a fiddle of it at http://jsfiddle.net/5ttGs/ It's really simple so far as this kinda paused my progress. Click it a couple times and enjoy 10000+FPS gameplay

有帮助吗?

解决方案

Fixed the problem with the help of cocco. Basically the onclick event called the disp function every time the canvas was clicked. Because the disp function had a requestAnimationFrame frame in it, it called it twice as much every second, resulting in the influx of frames. In order to fix I simply got rid of the disp in canvas.addEventListener

function mouse_up() {
var matches = 0;
var overlap = 69;
mouse.up = false;
console.log("clicked", mouse.x,mouse.y);
disp();
}

You can find the result here: http://jsfiddle.net/5ttGs/

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top