Hey guys!
So idea is very simple:
I have two scenes: start and game.
In start scene you can see button to go to game scene.
In game scene you can see box and ground. When box collides with ground we will go to start scene.
And so on. Where is no mechanics, box just falling and thats all.
In game scene we use 3 events: createScene, enterScene and exitScene.
createScene method creates display objects and adds them to scene view.
enterScene method adds physics bodies (using those display objects) and collision event listener.
exitScene method removes physics bodies and collision event listener.
Problem here that when collision occurs I try to change scene to start and of course exitScene method triggers and I get an error:
ERROR: physics.removeBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event.
Well timer.performWithDelay helped with removing bodies and event listeners properly, but I think its not the best workaround. Mby its not great idea to remove bodies and listeners in exitScene event.
I’ll be very happy to get some links to articles with best practises working with physics and storyboard.
You can check source code here: https://gist.github.com/2tunnels/9668318
Thank you