-3

The File holds the function I need:

func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. }

but I don't know how to reference the GameScene to pause it. My goal ist to stop everything inside the GameScene with the command:

self.view.isPaused = true,

but I can't reference the view :/ Thanks for help in advance!

  • Access the view controller hosting the game scene. – El Tomato Mar 17 '19 at 22:55
  • Your scene automatically pauses when your app goes into the background. It is one of the annoying "features" of SpriteKit, because if you have any nodes paused prior to sending the app to the background, they will become unpaused when you return – Knight0fDragon Mar 18 '19 at 18:30

1 Answers1

-1

Access the viewController where your scene is, ie if your gameScene is in a viewController named gameViewController:

  let vc = gameViewController()
   vc.view.isPaused = true

or

   vc.GameScene.view.isPaused = true
Peter Ruppert
  • 1,067
  • 9
  • 24
  • Definitely not the answer because `gameViewController` does not exist – Knight0fDragon Mar 18 '19 at 18:28
  • @Knight0fDragon he doesnt state where his GameScene is, so I am using ‘gameViewController’ as a placeholder for if it is inside a ViewController – Peter Ruppert Mar 18 '19 at 18:30
  • You think that makes it any better? if it is inside the view controller, you would say `self`. Otherwise you need to provide a delegate, all of which are terrible ideas since there exists a notification for when your app changes states. – Knight0fDragon Mar 18 '19 at 18:33
  • `vc.GameScene.view.isPaused = true` also fails btw because GameScene does not have access to `view` unless vc has a variable named `GameScene`, which is not following propert naming convention. – Knight0fDragon Mar 18 '19 at 18:36
  • 1
    When you are making answers on SO, if the code you provide does not work by creating a new project, or by using code explicitly provided by the user, then you need to explain where it comes from, otherwise the OP will never be able to get it to work unless they try guessing what you meant. – Knight0fDragon Mar 18 '19 at 18:39
  • @Knight0fDragon what I meant is to do the equivalent of self.view.isPaused, from appDelegate which instead of self you would declare the VC i.e gameViewController (where the game scene is) and instead of self do vc.view.ispaused. – Peter Ruppert Mar 18 '19 at 18:40
  • @Knight0fDragon okay I am new to answering but that is good advice I will make sure to use – Peter Ruppert Mar 18 '19 at 18:41