Going to next level makes objects move

Wondering if anyone has encountered this before. If I choose my level from the level select menu, the menu loads all items fine. If I reload the level using my reload button it works fine. The issue lies in when I finish the previous level and press the "next" button to go to the next level. On some of my levels when I transition from the previous level to the next one, the physics objects seem to spawn in slightly different areas. This is apparent when I have physics objects very close to each other (i.e. stacked crates). This may cause the objects to react to each other, possibly topple over, fall through the floor etc. If I reload the level, it works just fine. Anyone else encounter this?

I had a similar problem. What ended up working for me was to make sure to clean up the physics world completely before starting the next level. That meant iterating through all the physics bodies in the world and deleting them before loading the next level.

I also had to call physics.stop() before loading the next level and restarting it. (be careful with that! There's a random crash bug that occurs if you call physics.stop() while there are still physics bodies in the world. You have to delete EVERYTHING in the world before calling physics.stop.)

Without doing the above I would get some weird phantom physical effects on certain physical objects when I started the next level.

Thanks for your reply XenonBL. Is it possible those physics items from the previous level are most likely overlapping my new physics items on the next level, causing them to interact? This would make a lot of sense. I will try what you suggest. Thank you very much, appreciated.

For me the symptoms suggested that the last physics step from the previous level was still playing itself out and somehow interacting with objects in the new level, even though the old objects were no longer visible.

By the way, I don't think this issue has anything to do with Director. At least, I know that's true for my app since I'm not currently using Director. Box2D just seems to be a finicky beast to control, and I suspect Ansca's implementation of it has introduced a few more peculiarities.

views:1346 update:2011/10/12 18:33:00
corona forums © 2003-2011