2
,我發現了以下錯誤:的RangeError使用requestAnimationFrame
RangeError: Maximum call stack size exceeded.
該行:
requestAnimFrame(Game.loop());
在這一塊代碼:
var Game = {
canvas: null,
context: null,
targetFps: 60,
init: function() {
canvas = document.getElementById('main-canvas');
context = canvas.getContext('2d');
// Resize canvas to match content
var content = document.getElementById('primary-content');
canvas.width = content.offsetWidth;
canvas.height = content.offsetHeight;
window.requestAnimFrame = (function() {
return window.requestAnimationFrame || // Chromium
window.webkitRequestAnimationFrame || // WebKit
window.mozRequestAnimationFrame || // Mozilla
window.oRequestAnimationFrame || // Opera
window.msRequestAnimationFrame || // IE
null;
})();
this.loop();
},
loop: function() {
requestAnimFrame(Game.loop());
},
update: function() {
// ...
},
draw: function() {
// Clear background with black
context.fillStyle = '#000';
context.fillRect(0, 0, canvas.width, canvas.height);
}
};
Game.init();
這也可能是明顯的東西我」俯瞰,但任何幫助將不勝感激。謝謝!
謝謝!這很笨拙。 :) – jlowgren 2012-01-07 18:55:05