Hi, I’m trying to implement a pause function for my app, so that at certain times all the sprites and physicsbodies stop moving and I can display some other stuff. Does anyone know a good way to do this? pauseSchedulerAndActions() doesn’t stop the physicsBodies (and the associated sprites) from updating, and pausing using the director means that I can’t continue any UI animations in the scene.
Could you do something like: sprite->unscheduleAllSelectors(); sprite->getPhysicsBody()->setVelocity(cocos2d::Vect(0,0)); sprite->getPhysicsBody()->setVelocityLimit(0);
Or I also see a function: void setUpdateRate (int rate)
Perhaps using 0 may stop updating. I haven’t tried it.
@slackmoehrle, thanks very much, what you’ve said doesn’t quite work (setUpdateRate doesn’t seem to work, at least not with zero). However, the following does work for pausing the physicsWorld:
@sillyatom, what you’re suggesting might work if I was manually updating the world, but it’s handled by the physicsWorld so I can’t change the update function (as far as I know).
I have a situation where I need to pause the physics world in order to stop all things in it from moving around for awhile… Then I need to have a few of those things to start running again, they won’t collide with any other object unless it’s “alive” too. I was thinking it would be easiest to use another PhysicsWorld for this but it seems that cocos2d-x only supports one PhysicsWorld per scene? Is there any other way to pause just one object? FYI I pause the world like this:
But this time recursively, to gameplayArea and all itschildren nodes.
And use the respective resume methods to go continue everything.
///
Please note that updates will still be called, and the game time will still tick, so you can implement your menus freely with animations and all, and even read input from HTML5 joypads, for example