I have a problem pausing my game. I have a func that automatically spawns new "block" every sec and moves it across the screen. But when I set paused = true
, everything is paused and I cannot animate my pause label. Is there a way to exclude something from pause? I've searched and nothing works for me. There's the SKAction
that cannot be paused, unless paused = true
.
//this happens every 1 sec
block.color = UIColor.blackColor()
block.position = CGPoint(x: CGFloat(frame.width), y: generateSetting)
block.physicsBody = SKPhysicsBody(rectangleOfSize: block.size)
block.physicsBody?.categoryBitMask = BodyType.block
block.physicsBody?.contactTestBitMask = BodyType.ground
block.physicsBody?.contactTestBitMask = BodyType.bobby
block.physicsBody?.allowsRotation = false
block.physicsBody?.affectedByGravity = false
block.physicsBody?.dynamic = false
block.physicsBody?.restitution = 0
block.zPosition = 1
block.shadowedBitMask = 1
self.addChild(block)
Use SKNodes to only pause the layers you want. Create node for the pause layer:
let gameLayer = SKNode()
Then to add things to the layer:
gameLayer.addChild(pausedNode)
addChild(gameLayer)
You would also do this for a game layer so you can simply only pause the game layer as that pauses all its children so if you create another layer called noPauseGameLayer
for example, you wouldn't be pausing whatever is on that layer.
Now, to pause only the layer that you want to pause, do this:
Swift 3
gameLayer.isPaused = true
Swift 2
gameLayer.paused = true
If you have any further questions ask me in the comments