-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Chapter 11: Pausing - Home Button #3
Comments
Hi Mark, The idea is that we are registering for notifications in GameScene called "Pause" and "Resume" in the didMove(to:) method. // Register notifications for "Pause"
NotificationCenter.default.addObserver(self, selector: #selector(statePaused), name: NSNotification.Name(rawValue: "Pause"), object: nil)
// Register notifications for "Resume"
NotificationCenter.default.addObserver(self, selector: #selector(resumeGame), name: NSNotification.Name(rawValue: "Resume"), object: nil) The chain of events that happen when the game comes back into the foreground to resume the game go like this.
func applicationDidBecomeActive(_ application: UIApplication) {
// Resume the view
let view = self.window?.rootViewController?.view as! SKView
view.isPaused = false
// Post message to Resume the game
NotificationCenter.default.post(name: Notification.Name(rawValue: "Resume"), object: nil)
}
func resumeGame() {
// Run a timer that resumes the game after 1 second
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(stateResume), userInfo: nil, repeats: false)
}
func stateResume() {
state = previousState
gameNode.speed = 1.0
if kDebug {
print("Resuming")
}
} Let me know if that helps you out. Jeremy |
Thanks Jeremy, I did do the following :
I assume that the expected behavior would be that the Game just resumes as if you would just hit pause/play within the game ... but it does not. I would also agree that the speed=1.0 should start everything. Will have a look into it, maybe I can find it or it is just something local for me. Cheers, |
Okay, thank you for detailing your steps. If I understand correctly you are pausing, and then hitting the home button. The game is not resuming after bringing it back into the foreground and pressing the resume button. Correct? Yes this is a bug. It is written to be mutually exclusive, either pressing the home button or pressing the pause button. I will address this tonight when I get home and make an update. Thank you for pointing it out. Jeremy |
Yeah, that is exactly it. Looking through the code I thought that while the Pause vs. the Home Button is a bit different, logically it should work the same. -Mark |
Hey there,
the pause within the game tapping the pause/resume button works without problems, but if you pause and hit the Home button, return to the game the game will not resume but only the background seems to be resumed while player, meteors and stars are frozen so to say.
Cheers,
Mark
The text was updated successfully, but these errors were encountered: