在我的游戏中,我添加了iAd。
我想添加一些代码,告诉应用只在场景 GameOverScene 或 NewGameScene 时加载横幅,并让游戏场景远离任何广告。
我该怎么做? (相当新的obj-c)。
答案 0 :(得分:1)
当您将ADBannerView
的字母设置为0时,自动将被禁用,并且不会显示任何广告。因此,当调用该方法来启动游戏时,您还应该添加以下代码:
[myAdBanner setAlpha:0];
然后,当用户返回主菜单,或退出他们玩游戏的部分时,您应该添加以下代码:
[myAdBanner setAlpha:1];
如果您想在禁用或启用横幅视图时执行漂亮的动画,则可以执行以下操作:
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:(duration in seconds)];
[banner setAlpha:(0 to disable, 1 to enable)];
[UIView commitAnimations];
使用所有这些代码的示例,使用动画使横幅视图淡入和淡出是:
- (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
}