Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause SpriteKit game with Physics SKSpriteNode child

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?

like image 569
μ4ρκ05 Avatar asked Mar 09 '14 12:03

μ4ρκ05


2 Answers

Try setting your physicsWorld.speed to 0.0:

scene.physicsWorld.speed = 0.0

Apple SKPhysicsWorld Ref.

like image 58
AndrewShmig Avatar answered Oct 17 '22 21:10

AndrewShmig


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

self.scene.view setPaused:YES

like image 30
Amani Elsaed Avatar answered Oct 17 '22 21:10

Amani Elsaed