Pause SpriteKit Scene When Clicking on iAds

夙愿已清 提交于 2020-01-02 04:42:08

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/21892064/pause-spritekit-scene-when-clicking-on-iads

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!