0

我目前正在开发一个 javascript canvas 2D 游戏引擎,我遇到了一些关于requestAnimFrame. 在我看来,我做得正确,但一段时间后我收到以下错误(Uncaught RangeError: Maximum call stack size exceeded)

您可以在这里查看源代码:http: //snipt.org/vxij1

4

1 回答 1

1

我的猜测是这一行:

requestAnimFrame(this.mainGameLoop());

应该是这样的:

var self = this;
requestAnimFrame(function() {self.mainGameLoop()});

以便您的回调稍后作为回调调用,而不是立即执行。

于 2012-08-12T00:33:08.667 回答