Physics Objects "Bump" when restarting/switching scenes

EDIT: I put physics.stop() before the swap and now its an entirely new set of problems; sometimes physics doesn't initiate correctly in the next room, causing all sorts of errors with the simulator.

I'm having a problem with the director class. It doesn't produce any sort of code errors to show from the console, however it can make for some very odd effects in the game.

When I either restart a level or switch a level through director, the physics bodies seem to be (I assume) overlapping for a split second with the newly created scene, causing them to bump any others that happen to be at a position. For example, if i restart a level that has a stationary ball, or skip to a new level with a ball in the same position, the new one will be knocked slightly to either side and start rolling.

I have a hazard that pops up a "level failed" screen when your ball collides with it, and upon skipping a level, if there is a hazard in that position in the next level, the first play of that level instantly says failed. There is a similar problem with the next levels goal being in the same position.

I've tried deactivating certain bodies before switching levels, however it had no affect. Can anyone help me out here?

Thanks!

I've had a similar experience. I didn't use physics.stop() to work around it. It may not work for you (because it depends on what your screen looks like before the scene changes for this to work), but one of my work around was to make the "hazard" in the old scene invisible and move them way off screen before scene changes.

I've tried that before with no luck. I'll give it another go when I can though.
Edit: Alright easy fix; Creating a go-between "loading level" empty room that it goes to beforehand.

That sounds cool, Shady Guy. So, how does go-between "loadingLevel" work?

When the screen transitions from level1 to level2, you change the scene from level1 to loadingLevel, and then automatically change scene again to level2?

Do you use timer to load and unload loadingLevel? I'd love to know how you implemented it.

My loadlevel.lua is set up so it can be used universally by all the levels - before the director switches the scene, I set a global variable to the level that will be loaded next. That's either the current level, or the next level, depending if the context is a restart, victory, or skip. It goes to loadlevel, which is empty except for a loading level screen. A timer is set to a second or so just for tidiness, although technically a millisecond change should work as well, then it changes to the level indicated by the variable.
The variable in my case is just set to the name of the levels lua file, so director can easily access that without any fiddling.

That sounds really good!

views:1475 update:2011/10/22 17:28:16
corona forums © 2003-2011