I succeeded to pause a scene game with this code:
override func touchesBegan(touches: NSSet!, withEvent event: UIEvent!) {
var touch:UITouch = touches.anyObject() as UITouch
pauseText.text = "Continuer"
pauseText.fontSize = 50
pauseText.position = CGPointMake(self.frame.size.width/2, self.frame.size.height/2)
/* bouton play/pause */
var locationPause: CGPoint = touch.locationInNode(self)
if self.nodeAtPoint(locationPause) == self.pause {
println("pause")
addChild(pauseText)
pause.removeFromParent()
paused = true
}
if self.nodeAtPoint(locationPause) == self.pauseText {
pauseText.removeFromParent()
paused = false
addChild(pause)
}
}
But I have a problem.
All random interval the game create objects and display them on the screen. When I pause the game it continues to create objects in background and when I resume the game all objects created during the pause appear in same time on the screen.
How can i fix it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…