以下作品:
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 一次。我已经搞砸了很长时间,似乎无法找到一种让它递归运行的方法。