I am creating my first game in SpriteKit. I am trying to pause my GameScene and then run some animations via SpriteKit. The issue was that if I pause the scene using self.view?.isPaused = true
everything stops. After searching around I found that the way to do this is to add another node to the scene and make everything else that you want to pause, child nodes of that node. I am trying to do that but haven't been successful. This is the code that I have
var worldNode:SKNode?
override func didMove(to view: SKView) {
worldNode = SKNode()
self.addChild(self.worldNode!)
let spriteNode:SKSpriteNode = SKSpriteNode(imageNamed: "red_ball")
spriteNode.size = CGSize(width: 40, height: 40)
spriteNode.physicsBody = SKPhysicsBody(circleOfRadius: 15)
spriteNode.physicsBody?.isDynamic = true
self.worldNode?.addChild(spriteNode)
spriteNode.physicsBody?.applyImpulse(CGVector(dx: 10, dy: 10))
self.worldNode?.isPaused = true
//self.view?.isPaused = true
}
when I run this I see the ball moving on the screen which should not happen according to my understanding, since I am pausing the worldNode
and the spriteNode
is child node of that. If I use self.view?.isPaused = true
to pause the scene, then the ball is stationary as expected. Am I missing something ? how can I add nodes to the worldNode
and then just pause only those nodes by pausing worldNode
. Thanks !