user3435781
user3435781

Reputation: 61

Hiding iAd banner in gameplay scene?

in my game, I have added iAd.

I want to add some code that tells the app to only load the banner when the the scene is GameOverScene or NewGameScene and leave the gameplay scene clear of any ads.

How do I do this? (Fairly new to obj-c).

Upvotes: 1

Views: 1012

Answers (1)

Jojodmo
Jojodmo

Reputation: 23616

Automatically, when you set the alpha of an ADBannerView, to 0, it will be disabled, and no ad will be shown. So, when the method is called to start the game, you should also add this code:

[myAdBanner setAlpha:0];

then, when the user goes back to the main menu, or exits out of the part where they play the game, you should add this code:

[myAdBanner setAlpha:1];

If you wanted to do a nice animation when the banner view is disabled or enabled, you could do this:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:(duration in seconds)];
[banner setAlpha:(0 to disable, 1 to enable)];
[UIView commitAnimations];

An example of using all of this code, using an animation to make the banner view fade in and out is:

- (IBAction)startGame{
    //user starts the game
    [UIView beginAnimations:nil context:NULL];//initiate the animation
    [UIView setAnimationDuration:1];//make an animation 1 second long
    [banner setAlpha:0];//disable the ad by making it invisible
    [UIView commitAnimations];//do the animation above
}

- (IBAction)endGame{
    //user wins, loose, or ends the game
    [UIView beginAnimations:nil context:NULL];//initiate the animation
    [UIView setAnimationDuration:1];//make an animation 1 second long
    [banner setAlpha:1];//enable the ad by making it visible
    [UIView commitAnimations];//do the animation above
}

Upvotes: 1

Related Questions