2

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. But after a few seconds of playing the game it freezes... I believe this is from too much recursion (i.e. 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.

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

Cheers

  • it would be useful if you posted your code, specifically the move function and the game loop. Ill look in the source for now though. – Jon Taylor Jul 03 '12 at 23:05
  • You could try cloning his GitHub repository. – Alex W Jul 03 '12 at 23:05
  • You seem to be recursivley calling move, by that I mean your calling move inside 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. – Jon Taylor Jul 03 '12 at 23:09

2 Answers2

0

You seem to be recursivley calling move, by that I mean your calling move inside 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.

Jon Taylor
  • 7,865
  • 5
  • 30
  • 55
0

Your clone function is screwed up. You call it on the document's body element somewhere, and that has circular references. You should be able to see this using a debugger. See How do you clone an Array of Objects in Javascript? and In Javascript, when performing a deep copy, how do I avoid a cycle, due to a property being "this"?.

Also, you should never ever use Object.prototype.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375