0

以下作品:

window.requestAnimFrame = (function(){
return  window.requestAnimationFrame ||
window.webkitRequestAnimationFrame   ||
window.mozRequestAnimationFrame      ||
window.oRequestAnimationFrame        ||
window.msRequestAnimationFrame       ||
function(callback){ window.setTimeout(callback, 1000 / 60); };
})();

function gameLoop() {
    requestAnimFrame(gameLoop);
}

但是,当我尝试使用模块模式打包功能时,如下所示:

var GameModule = {

    requestAnimFrame: function() { 
    return window.requestAnimationFrame ||
    window.webkitRequestAnimationFrame  ||
        window.mozRequestAnimationFrame     ||
    window.oRequestAnimationFrame       ||
        window.msRequestAnimationFrame      ||
    function(callback){ window.setTimeout(callback, 1000 / 60); };
   },

   gameLoop: function() {
       this.requestAnimFrame(this.gameLoop);
   }
};

// run the game
(function(){
    Game.gameLoop();
})();

...它只调用 requestAnimFrame 一次。我已经搞砸了很长时间,似乎无法找到一种让它递归运行的方法。

4

1 回答 1

0

固定的:

this.requestAnimFrame(this.gameLoop());
于 2013-04-01T17:47:56.703 回答