質問

I'm making a simple game and I would like to add an iAd at the top of the Game Over Screen. I could add it on to the UIViewController, but then it would show up while playing, which is something I don't want.

Is there a way to make the iAd appear only on a certain SKScene? Thanks for all your help!

役に立ちましたか?

解決

The most clean solution is to declare and implement a protocol to let the UIViewController know that it should hide the ad.

@protocol MySceneDelegate <NSObject>
- (void)hideAd;
- (void)showAd;
@end

@interface MyScene : SKScene
@property (weak) id <MySceneDelegate> delegate;
@end

View controller that shows the scene should implement a hideAd method and set itself as a delegate of the scene. Example:

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view, etc.
    ...

    // Set the delegate
    [scene setDelegate:self];

    // Present the scene.
    [skView presentScene:scene];
}

Then in the scene you don't want to show an ad, you can call the hideAd method of the view controller which was set as a delegate:

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{
    /* Called when a touch begins */

    if ([_delegate respondsToSelector:@selector(hideAd)])
    {
        [_delegate performSelector:@selector(hideAd)];
    }
}

You can tell the view controller to show the ad in the same way. Hope it helps.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top