0

I can pause the game I have created no problem while I'm in the app. However, when I try and call the pause function I have created in the applicationWillResignActive function in App Delegate, it doesn't work, at all. So this is my code that I am trying to use in my App Delegate File.

func applicationWillResignActive(_ application: UIApplication) {
    GamePlayScene.instance.isPaused = true
    print("Game is Paused")
}

The print Statement gets called so I know the function is getting called. However, the game still stays active. I'm trying to call the same isPaused function that I am using in my GamePlayScene.

One thing that works is if I just use the normal pause feature in SpriteKit but, I can't find a way to resume the game after I open the app. For example, I can use this.

func applicationWillResignActive(_ application: UIApplication) {
    pause()
    print("Game is Paused")
}

This seems to work, but the whole app just opens up frozen and there is no way to keep going. What do y'all think?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Figured it out. Since I don't see anyone else that has the answer when involving a SpriteKit Game, I will post the answer. This is my code.

let notificationCenter = NotificationCenter.default
    notificationCenter.addObserver(self, selector: #selector(appMovedCameBack), name: Notification.Name.UIApplicationDidBecomeActive, object: nil)

@objc func appMovedCameBack() {
    print("App Came Back!")

    self.scene?.isPaused = true

    GamePlayController.instance.pauseBtn?.alpha = 0

    createPausePanel()
}

I am calling the function where I created the PausePanel and adding it to the scene. That is the createPausePanel() function. I am also setting the scene.isPaused = true. This is how I solved my issue.