使用swift和spritekit,如何在激活/移动到前景后阻止场景取消暂停?
我的AppDelegate中有以下代码:使用swift和spritekit,如何在激活/移动到前景后阻止场景取消暂停?,swift,sprite-kit,Swift,Sprite Kit,我的AppDelegate中有以下代码: func applicationDidEnterBackground(_ application: UIApplication) { NotificationCenter.default.post(name: NSNotification.Name(rawValue: "PauseGame"), object: self) } 在我的GameSecene.swift文件中,我有观察员: NotificationCenter.default.ad
func applicationDidEnterBackground(_ application: UIApplication) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "PauseGame"), object: self)
}
在我的GameSecene.swift文件中,我有观察员:
NotificationCenter.default.addObserver(self, selector: #selector(GameScene_split.pauseGame), name: NSNotification.Name(rawValue: "PauseGame"), object: nil)
下面是它调用的函数:
@objc func pauseGame() {
self.isPaused = true
isGamePaused = true
pauseButton.texture = SKTexture(imageNamed: "PlayButtonWhite")
}
好的,当按下home(主页)按钮,应用程序进入后台时,确实会调用pauseGame函数,因为当我单击返回应用程序时,pauseButton纹理已更改为“PlayButtonWhite”,但游戏不会暂停
关于如何在应用程序激活时阻止游戏自动取消暂停,有什么想法吗 当游戏恢复时,场景(不知何故)自动取消暂停 但是,您可以检查属性
isGamePaused
,然后再次暂停游戏
这是你的场景代码
override func update(_ currentTime: TimeInterval) {
guard !isGamePaused else {
self.view?.isPaused = true
return
}
}
让我知道它是否有效。这可能就是您要找的