简体   繁体   English

html5 canvas pacman game-javascript过多的递归

[英]html5 canvas pacman game - javascript too much recursion

I've been working on a fun little side project to customize the dale harvey's html5 canvas pacman game http://arandomurl.com/2010/07/25/html5-pacman.html and teach myself a bit of javascript at the same time. 我一直在做一个有趣的小项目,来自定义dale harvey的html5 canvas pacman游戏http://arandomurl.com/2010/07/25/html5-pacman.html并同时教自己一些JavaScript 。 But after a few seconds of playing the game it freezes... I believe this is from too much recursion (ie something needs to be closed?) but I'm under the impression that game loop needs to remain open to allow the continuous control and movement of the characters... correct? 但是在玩了几秒钟之后,它就冻结了...我认为这是因为递归过多(例如,是否需要关闭某些内容?),但我给人的印象是,游戏循环需要保持打开状态以允许连续控制角色的动作...对吗?

I'm a bit of a noob in the javascript game so any help would be great. 我在javascript游戏中有点菜鸟,所以任何帮助都会很棒。

http://bridgestreetcollective.harmonyapp.com/pacman/?password=test http://bridgestreetcollective.harmonyapp.com/pacman/?password=test

Cheers 干杯

You seem to be recursivley calling move, by that I mean your calling move inside move. 您似乎是递归地调用Move,这是指您在move内部的调用Move。 This is why your call stack is getting too big. 这就是为什么您的调用堆栈变得太大的原因。

You should be having a game loop where you call move from, dont call move from inside itself. 您应该有一个游戏循环,您可以在其中调用移动,而不要在内部调用移动。

Your clone function is screwed up. 您的clone功能搞砸了。 You call it on the document's body element somewhere, and that has circular references. 您可以在文档的body元素某处调用它,并且具有循环引用。 You should be able to see this using a debugger. 您应该能够使用调试器看到它​​。 See How do you clone an Array of Objects in Javascript? 请参阅如何在Javascript中克隆对象数组? and In Javascript, when performing a deep copy, how do I avoid a cycle, due to a property being "this"? 在Javascript中,执行深度复制时,由于属性为“ this”,如何避免循环? .

Also, you should never ever use Object.prototype . 另外, 永远不要使用Object.prototype

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM