Question

I have a SKSpriteNode with a dynamic physics body on a SKNode *_fgLayer.

Now, when I pause or unpause the game I want that SKSpriteNode to remain in place and not rotate or fall down. If I simply use _fgLayer.paused = YES; the SKSpriteNode does not stay in place but rather rotates and falls down. If I set physicsBody.dynamic = NO; when paused and physicsBody.dynamic = YES; when unpaused it works.

However, after a few tries I always get the following crash:

"Assertion failed: (typeA == b2_dynamicBody || typeB == b2_dynamicBody), function SolveTOI, file /SourceCache/PhysicsKit/PhysicsKit-4.6/PhysicsKit/Box2D/Dynamics/b2World.cpp, line 670."

So, I guess setting a physicsBody.dynamic = NO; and back does not work.

Does anyone have an idea of
how to pause dynamic physics bodies to remain in place when the game is paused?

Was it helpful?

Solution

Try setting your physicsWorld.speed to 0.0:

scene.physicsWorld.speed = 0.0

Apple SKPhysicsWorld Ref.

OTHER TIPS

Setting scene.view.paused = YES works for me - specially when there are actions running on the child node.

self.scene.view setPaused:YES

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top