Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pause SpriteKit Scene When Clicking on iAds

I am working on a SpriteKit project and I'm struggling to pause the game when the iAd is clicked, and unpause when the iAd is dismissed. The main problem is pausing the Scene from the ViewController, I know that if I want to pause the Scene from the Scene.m I should use the code

    self.scene.view.paused = YES;

however this code doesn't work in the ViewController.

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
//pause game
}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner
{
//unpause game
}

I know that I would like to pause the game in the section above but I'm having trouble finding the resources to know how to perform this. Any help is appreciated, thanks.

like image 255
nick Avatar asked Feb 19 '14 20:02

nick


1 Answers

If you have an SKView that's presenting a scene, you can call pause from within its ViewController like this:

Objective-C:

SKView *skView = (SKView *)self.view;
skView.scene.paused = YES;

Swift

let skView: SKView = self.view as! SKView
skView.scene.paused = true
like image 121
Batalia Avatar answered Oct 24 '22 04:10

Batalia