game exits from pause state after resuming it from background in swift

后端 未结 1 1275
悲&欢浪女
悲&欢浪女 2021-01-07 00:41

I\'m developing a game with SpriteKit that can be paused during execution and can be resumed. But I have a problem with applicationDidEnterBackground when the h

相关标签:
1条回答
  • 2021-01-07 00:52

    Pretty much the same as here

    AppDelegate:

    func applicationWillResignActive(application: UIApplication) {
        NSNotificationCenter.defaultCenter().postNotificationName("PauseGameScene", object: self)
    }
    

    GameSceneViewController:

    override func viewDidLoad() {
        super.viewDidLoad()
    
        NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("pauseGameScene"), name: "PauseGameScene", object: nil)
    }
    
    func pauseGameScene() {
        if self.skView.scene != nil {
            self.skView.paused = self.skView.scene.paused = true
        }
    }
    
    0 讨论(0)
提交回复
热议问题