thebro
thebro

Reputation: 305

Swift game won't stay paused

I'm having difficulty pausing the game when I leave and switch back to it.

I'm trying to pause the SKSpriteNode called main, which contains all my sprites, when the view returns from the background. In-game, I can touch the pause button and the game pauses, and the resume button and it resumes.

This is my code:

func didBecomeActive() {
    println("didBecomeActive")
    main.paused = true
}

The first time this runs is when the app opens for the first time, and everything is paused as it should be. The second time, is when it returns from the background, and suddenly all the animations (SKActions, particles, etc.) start working.

I've confirmed that the method is running, and I've also tried setting main.paused to false and then true, and even self.paused to true. Nothing works.

I'm completely stumped. Anyone know what the issue is here?

Upvotes: 3

Views: 483

Answers (1)

Amani Elsaed
Amani Elsaed

Reputation: 1598

Setting self.scene.paused = YES should fix this. I have tried it with a game I am developing and it works fine.

Just set self.scene.paused = YES when the game enters the background, then when it return to the foreground, it should stay paused till you resume it, i.e. set self.scene.paused = NO.

Upvotes: 2

Related Questions