0

I have some spritenodes with SKAction(); They are child's of sknode with name world

If I press the pause button in the game its animation of the spirenodes

func pause(){
    if(isGamePaused)
        isGamePaused = false;
        world.paused = false;
    } else {
        isGamePaused = true;
        world.paused = true;
    }
}

But I cannot pause the game when is going in the background

 NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("goBG:"), name: UIApplicationWillResignActiveNotification, object: nil);

func goBG(sender: AnyObject){
    self.isGamePaused = true;
    self.world.paused = true;

    println("bg"); // called
    println(world.paused);// return true
}
  • SpriteKit automatically pauses when your app moves to the background and resumes when the the app is active. – 0x141E Jan 21 '15 at 19:38

2 Answers2

0

You can add either try to observe the UIApplicationDidEnterBackgroundNotification instead of your UIApplicationWillResignActiveNotification notification, or you can call a function in your AppDelegate method applicationDidEnterBackground where you pause the game.

Christian
  • 22,585
  • 9
  • 80
  • 106
0

if anyone is still interested. There's a solution for this issue here:

SpriteKit Autoresumes and auto pauses iOS8

Community
  • 1
  • 1
hamobi
  • 7,940
  • 4
  • 35
  • 64