【发布时间】:2017-06-30 20:44:38
【问题描述】:
我了解这两种方法之间的区别,但我想知道在执行诸如暂停 SpriteKit 游戏之类的操作时,使用 UIApplicationWillResignActive 与 UIApplicationDidBecomeActive(或 UIApplicationDidEnterBackground)相比是否有缺点。我一直在浏览网站上的线程,并注意到通常在回答询问如何暂停 SpriteKit 游戏的问题时,建议使用 UIApplicationDidBecomeActive 和 UIApplicationDidEnterBackground,而不是 UIApplicationWillResignActive。由于 UIApplicationWillResignActive 也会暂停游戏以响应 Siri/Calls,在处理暂停 SpriteKit 游戏等时,这不是更好的方法吗?或者使用它有什么缺点吗?
下面我有我的通知和暂停功能:
NotificationCenter.default.addObserver(self, selector: #selector(self.pauseGame), name:NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
//OR
NotificationCenter.default.addObserver(self, selector: #selector(self.pauseGame), name:NSNotification.Name.UIApplicationWillResignActive, object: nil)
暂停功能:
func pauseGame(){
print(self.scene?.isPaused)
if sceneIsPaused == true || isGameOver == true{
return
}
leftMobGenTimer.invalidate()
rightMobGenTimer.invalidate()
genDragonTimer.invalidate()
checkNinjaTimer.invalidate()
chiStrikeTimer.invalidate()
randCoinTimer.invalidate()
print("Timer stopped?")
if soundEnabled == true{
player.pause()
}
self.scene?.isPaused = true
sceneIsPaused = true
makePauseView()
}
【问题讨论】:
标签: ios swift sprite-kit