1
votes

I am designing a SpriteKit game in swift, and inside my gameplay SKScene I have a method called when I want to pause the game. It looks like this:

func pause() {
    view?.paused = true
}

The game pauses perfectly, but after a seemingly arbitrary amount of time (1 second to 120 seconds), the game just unpauses/resumes gameplay, without ever calling my resume() method. I am aware that sprite kit resumes gameplay automatically upon the app becoming active, but I have set a breakpoint in applicationDidBecomeActive, and it is not called. Does anyone know why this is happening?

I know I could set my own paused property and check it every update loop, but I much prefer this elegant solution if I could get it to work!

1
so wait.. the game resumes itself while it's still active, or when you come back into the app? - hamobi
While it is still active - mogelbuster
how about you delete your resume method altogether and see if it still resumes.. or at least put a breakpoint in there and check where its being called from - hamobi
the resume method is never called - mogelbuster
@mogelbuster Where do you call your pause() method ? Also I am just curious does showPauseScreen() is executed ? - Whirlwind

1 Answers

0
votes

The problem was my implementation of ADBannerViewDelegate. Here is the culprit:

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    skView.paused = false
    println("bannerView:didFailToReceiveAdWithError called inside GameViewController class")
}

I solved the problem by putting those println calls inside every method that had a .paused = false statement. Most of the time the banners load fine, but every once in a blue moon they fail and call that method.