Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

My asteroids game acts strangely


Recommended Posts

You know when you seem to explode for no good reason?  What's happening is, that arcade physics bodies, are showing up for a few seconds in random places on the screen, causing you to die when you touch one of them.  I've set this up so I can see exactly where the physics bodies bounding boxes are, I cannot for the life of me figure out what is causing random physics bodies to pop in and then disappear again.


Would any of you guys be so kind, as to take a look at my code and see if you can spot anything.  I realize it may look bad, but I tried to comment it.


I will attach the whole projects, you'll notice the js folder has all the source files.


The source files you will be interested in is AsteroidHandler.js and Game.js --


Test the game out and go through 2 levels by shooting rocks, and eventually you see these colored squares blip in and out.


Anyways please tell me something I've over looked, or don't hesitate to ask me if you don't understand any of my terrible code.




Link to comment
Share on other sites

I'm looking at it, I haven't found anything blatantly wrong, yet.


Since the code is a little bit long it will take some time to figure where the bug might be.

Besides, I haven't experienced it, everything goes as supposed.


Would be more helpful if you could isolate the particular moment, or course of actions when it seems to happen everytime.



Btw, the game seems very laggy/slow, don't know if it's on purpose, if it's because of the use of game.time to slow down actions or because debug is activated, or because something is utterly wrong in the way you built things.



I'll post here if I stumble on something.


Meanwhile, if you could provide more precise informations concerning the bug, because I haven't experienced it, yet.

Link to comment
Share on other sites

It's laggy because the debug functions for drawing are expensive.  You should see translucent colored squares over the asteroid graphics themselves.


I can't really provide much more specific information.  The phsyics bodies will appear for a few seconds and then disappear, I think related to when it leaves or comes onto the screen, also happens when you shoot an asteroid and it explodes, a colored square will appear in some random place on the screen.  If you notice in the image below the two squares without asteroid graphics circled in red.  In the next moment they'll disappear.  asteroid bodies from any of the asteroid groups (primary or clones) will pop in and disappear like that.  I know these are actual bodies because you can collide with them (it was the reason there seemed to be 'phantom' asteroids, or the player died for no explicable reason).


It's all I can really say about it, although it seems to happen when an asteroid crosses the edges of the screen (and then also when you shoot an asteroid)


The fact I get the asteroid clones via index, could be a possible problem (that is if the index returned isn't the proper clone) -- if this makes any sense to you.



Just in case you don't have permission to download the zip file because you're not a member of this board, here it is on dropbox - https://dl.dropboxusercontent.com/u/32895233/sroids.zip

Link to comment
Share on other sites

Okay I have a much better idea of what's going on.  When I removed the code that turned offscreen asteroids invisible, and then the spawning code and the collision code, I noticed that those random bodies did not appear.  So I put the collision code back, and then it would do it when i shot an asteroid.  another curious thing was that with the visibility code still disabled the bodies of the clone sprites would be off a little bit.  So my thought is that those phantom bodies are essentially bodies that haven't been updated since I only update the clone's position instead of making it move with arcade physics.


So with a few modifications I believe I can fix this.  It will involve setting up the physics to work on the clones, and move them at the same time instead of relying on the primary's position.  Hopefully this will fix the problem since all asteroids will now be in sync.


I'll let you know how it goes.

Link to comment
Share on other sites

Late to the party again, but there is a valuable lesson in there I just can't pass up:


When there's something weird you can't debug the usual way, one way to narrow it down is iteratively removing parts of the program while retaining the bug. In the end you'll end up a very simple demonstration of the issue you can share on forums, or even attach to a bug report.

The point here is trying to come up with the simplest program that DOES have the bug.

Link to comment
Share on other sites

Well that's sort of what I did.  I couldn't possibly think of what to do, so I started removing parts that I thought were related.  So I'm going to attempt to rectify the situation here, and see if that helps anything.


I did just make sure it was using the same velocity, but I still have the problem... it's related to velocity and what not, I figured if I updated the clones velocities to match the primary it would stop the bodies from popping in too late.  Seemed to sort of work, but is not a permanent solution.


I guess I should just start my asteroids game from scratch.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...