I'm struggling with this and can't seem to find much reference to go on.
I am using the requestAnimFrame that was written up by Google:
requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function FrameRequestCallback */ callback, /* DOMElement Element */ element) {
window.setTimeout(callback, 1000/60);
};
})();
I have a function "init" which sets up my game. That then calls update which is the game loop which calls render to draw to canvas. If you ignore requestAnimFrame - each individual part works fine. Once I place a call to requestAnimFrame in though, I either get "too much recursion" error or FF just crashes.
My code in update() is as follows:
game.update = function()
{
stats.update();
fps.innerHTML = stats.getFPS();
// Render objects
game.render();
// Continue game loop
requestAnimFrame(game.update());
}
stats.update just updates the FPS counter. So you can see, this function doesn't do a lot. My game.render function just draws a load of tiles onto the canvas and that works fine.
Any suggestions?
Thanks!
Chris