问题
My game pauses ok when home button is pressed. But it doesn't when I get a call. Its actions are resumed when the game becomes active. I don't get the difference between getting a call and pressing HB. Please help me out.
Thanks.
func pauseGame(){
initResumeButton()
pause.removeFromParent()
gamePaused = true
self.paused = true
}
func resumeGame(){
resume.removeFromParent()
initPauseButton()
gamePaused = false
self.paused = false
}
func registerAppTransitionObservers(){
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillResignActive", name: UIApplicationWillResignActiveNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationDidEnterBackground", name: UIApplicationDidEnterBackgroundNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "applicationWillEnterForeground", name: UIApplicationWillEnterForegroundNotification, object: nil)
}
func applicationWillResignActive(){
if !gamePaused && state != .GameStarting{
pauseGame()
}
}
func applicationDidEnterBackground(){
self.view?.paused = true
}
func applicationWillEnterForeground(){
self.view?.paused = false
if gamePaused{
self.paused = true
}
}
来源:https://stackoverflow.com/questions/27262903/pausing-game-during-call-difference-between-getting-a-call-and-pressing-home-bu