I have set up the following jsFiddle http://jsfiddle.net/ZbhQY/4/
Im using a small requestAnimationFrame polyfill and returning the result to window.reqeuestAnimFrame this all works fine and all calls to this function work as expected.
If i change this to return to game.reqeuestAnimFrame and replace all calls to window.reqeuestAnimFrame to the new game.reqeuestAnimFrame it no longer works.
Could someone please explain why this is the case and what i could do in order to make this work?
Thanks.
requestAnimationFramemust have a context ofwindowto function properly.You can rewrite your call as:
and it will function as expected.
The error you were running into is because
requestAnimationFrameexpects its context (this) to bewindow, but instead its context wasgame.http://jsfiddle.net/ZbhQY/5/
Alternatively, you could rewrite your
requestAnimFramegetter like so:This would allow you to call
game.requestAnimFrame(game.run)as you would expect.