Pausing game during call, Difference between getting a call and pressing home button?

老子叫甜甜 提交于 2019-12-10 10:51:30

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!