在我的游戏中,我增加了iAd。
我想添加一些代码,告诉应用程序只在场景是、GameOverScene、或NewGameScene时才加载横幅,并在游戏场景中清除任何广告。
我该怎么做?(对obj-c来说相当新)。
发布于 2014-03-22 17:25:07
自动地,当您将一个ADBannerView的alpha设置为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
}https://stackoverflow.com/questions/22549754
复制相似问题