문제

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?

도움이 되었습니까?

해결책

Try setting your physicsWorld.speed to 0.0:

scene.physicsWorld.speed = 0.0

Apple SKPhysicsWorld Ref.

다른 팁

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

self.scene.view setPaused:YES

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top