我成功地用这段代码暂停了一个场景游戏:
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)
}
}
但是我有一个问题。 游戏创建所有随机间隔对象并将它们显示在屏幕上。当我暂停游戏时,它会继续在后台创建对象,当我恢复游戏时,暂停期间创建的所有对象都会同时出现在屏幕上。
我该如何解决?
最佳答案
当 SKView 暂停时,您不能将 SKLabelNode(或其他任何东西)添加到场景中。您将需要返回到运行循环,以便在暂停游戏之前添加您的文本。这是一种方法:
// Add pause text or button to scene
addChild(pauseText)
let pauseAction = SKAction.run {
self.view?.isPaused = true
}
self.run(pauseAction)
关于swift - SpriteKit 和 SceneKit – 如何完全暂停游戏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25824984/