Hello! There is a function that pauses the game.
func pauseTheGame() { self.scene?.isPaused = true //так же здесь прописано несколько других параметров, типа появление надписи, кнопок и т.д. } This function is called in two cases.
1) When the player presses the pause button during the game.
2) When the application is sent to the background.
But there is one small problem with notifications. A small code example:
From AppDelegate
func applicationWillResignActive(_ application: UIApplication) { NotificationCenter.default.post(name: NSNotification.Name(rawValue: "goToBackground"), object: self) } From the game scene:
NotificationCenter.default.addObserver(self, selector: #selector(GameScene.pauseTheGame), name: NSNotification.Name("goToBackground"), object: nil) - The first problem is that when the application is minimized, the game is paused, i.e. function is called and everything goes on as usual. But when the application becomes active again, the game itself turns off the pause and the game continues. That is, the value of the pause somehow changes itself to the value "false". While the rest of things, such as buttons and text, remain in place. Tell me what could be the problem?
- As I said above. The pause function is called either when the button is pressed or when it is minimized. I would like to know how to make the function not called twice. That is, if the player paused, and after that he also turned off the application. That is, the function is called twice. And you have to press the button "PLAY" twice.