Spritekit - Keep the game paused when didBecomeActive

前端 未结 1 1627
隐瞒了意图╮
隐瞒了意图╮ 2020-12-20 07:56

I have a pause system with a function and a button and it works perfect, i know when the app enters background it automatically pauses and when it comes back it automaticall

相关标签:
1条回答
  • 2020-12-20 08:11

    In your scene or view, you should be able to handle pause by adding an observer to it

        NSNotificationCenter.defaultCenter().addObserver(self,selector:Selector("pauseGame:",name:"Pause",object:nil)
    

    Then you add a function to handle this

    func pauseGame(notification:NSNotification)
    {
        self.paused = true;
    }
    

    Now keep in mind I have found that in iOS 8 there is a bug where CBApplicationDidBecomeActive can cause undesirable results, so you need to override this in your SKView's class like this:

    class GameSceneView : SKView
    {
        ...//Other Code
        func CBApplicationDidBecomeActive()
        {
        }
    }
    
    0 讨论(0)
提交回复
热议问题