1

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!

mogelbuster
  • 1,066
  • 9
  • 19
  • 3
    so wait.. the game resumes itself while it's still active, or when you come back into the app? – hamobi Feb 17 '15 at 18:49
  • While it is still active – mogelbuster Feb 17 '15 at 18:57
  • 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 Feb 17 '15 at 19:01
  • the resume method is never called – mogelbuster Feb 17 '15 at 19:28
  • @mogelbuster Where do you call your pause() method ? Also I am just curious does showPauseScreen() is executed ? – Whirlwind Feb 17 '15 at 19:48
  • @Whirlwind I have simplified my code, and have found the same thing still happens. Please take a look at my edit. I call the pause() method inside touchesBegan – mogelbuster Feb 17 '15 at 20:22
  • What happens if you use scene.view.paused = true instead of view?.paused = true – Whirlwind Feb 17 '15 at 20:25
  • @Whirlwind If i use scene.view.paused = true I get the compile time error message: 'SKScene?' does not have a member named 'view' – mogelbuster Feb 17 '15 at 21:22
  • What about this: self.scene?.view?.paused = true It probably won't change anything, but still you can try... – Whirlwind Feb 17 '15 at 21:29
  • @Whirlwind I think this is because scene is a SKNode property of type SKScene? and view is a SKScene property of type SKView?. You either need to use forced-unwrapping scene!.view!.paused = true or optional chaining scene?.view?.paused = true. Or use a combination of the two scene?.view!.paused = true. Or scene!.view?.paused = true. I've tested all four, none are any different than view?.paused = true – mogelbuster Feb 17 '15 at 21:41
  • @Whirlwind the thing is, SKNode has a property scene which is of type SKScene? but SKScene itself is a descendant of SKNode, thus SKScene confusingly, has an infinite loop reference to itself through its scene property. Its scene property is equivalent to self. I could also do scene!.scene!.scene!.scene!.view?.paused = true (which I actually tried haha) and it is equivalent to view?.paused = true – mogelbuster Feb 17 '15 at 21:44
  • @Whirlwind I tried self.scene?.view?.paused = true, same thing :-( – mogelbuster Feb 17 '15 at 23:24

1 Answers1

0

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.

mogelbuster
  • 1,066
  • 9
  • 19
  • try doing this: if banner != nil { skiver.paused = false println("your println...")} and that should help you out – user2277872 Feb 18 '15 at 01:49