I have the following code in my AppDelegate:
func applicationDidEnterBackground(_ application: UIApplication) {
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "PauseGame"), object: self)
}
In my GameScene.swift file, I have the the observer:
NotificationCenter.default.addObserver(self, selector: #selector(GameScene_split.pauseGame), name: NSNotification.Name(rawValue: "PauseGame"), object: nil)
Here is the function that it calls:
@objc func pauseGame() {
self.isPaused = true
isGamePaused = true
pauseButton.texture = SKTexture(imageNamed: "PlayButtonWhite")
}
Okay, so when the home button is pressed and the app goes into the background, this pauseGame function is indeed called because when I click back into the app, the pauseButton texture is has changed to the "PlayButtonWhite", but the game is not paused.
Any ideas on how to stop the game from automatically unpausing when the app becomes active?