Admob横幅在Cocos2d 2.0中的集成/iphone游戏中的Admob横幅
有人知道如何在cocos2dv2中使用admob吗?所有文档都基于视图根控制器,cocos2d2只是以另一种方式运行Admob横幅在Cocos2d 2.0中的集成/iphone游戏中的Admob横幅,iphone,ios,cocos2d-iphone,admob,Iphone,Ios,Cocos2d Iphone,Admob,有人知道如何在cocos2dv2中使用admob吗?所有文档都基于视图根控制器,cocos2d2只是以另一种方式运行 我找到的唯一文件是:但对于像我这样的新手来说,这有点糟糕。如果有人能帮我,我太感激了 这是我的admob cocos2d工作代码:将createAdmobAds、showBannerView、HidebanerView和dismissAdView复制到您的类中 下面是COCOS2D2.0的检查 #import "GADBannerView.h" typedef enum _ba
我找到的唯一文件是:但对于像我这样的新手来说,这有点糟糕。如果有人能帮我,我太感激了 这是我的admob cocos2d工作代码:将createAdmobAds、showBannerView、HidebanerView和dismissAdView复制到您的类中 下面是COCOS2D2.0的检查
#import "GADBannerView.h"
typedef enum _bannerType
{
kBanner_Portrait_Top,
kBanner_Portrait_Bottom,
kBanner_Landscape_Top,
kBanner_Landscape_Bottom,
}CocosBannerType;
#define BANNER_TYPE kBanner_Landscape_Bottom //change this on need basis
@interface MyMainMenu : CCLayer
{
GADBannerView *mBannerView;
CocosBannerType mBannerType;
float on_x, on_y, off_x, off_y;
}
@implementation MyMainMenu
-(void)onEnter
{
[super onEnter];
[self createAdmobAds];
}
-(void)onExit
{
[self dismissAdView];
[super onExit];
}
-(void)createAdmobAds
{
mBannerType = BANNER_TYPE;
AppController *app = (AppController*)[[UIApplication sharedApplication] delegate];
// Create a view of the standard size at the bottom of the screen.
// Available AdSize constants are explained in GADAdSize.h.
if(mBannerType <= kBanner_Portrait_Bottom)
mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
else
mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerLandscape];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
mBannerView.adUnitID = MY_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
mBannerView.rootViewController = app.navController;
[app.navController.view addSubview:mBannerView];
// Initiate a generic request to load it with an ad.
[mBannerView loadRequest:[GADRequest request]];
CGSize s = [[CCDirector sharedDirector] winSize];
CGRect frame = mBannerView.frame;
off_x = 0.0f;
on_x = 0.0f;
switch (mBannerType)
{
case kBanner_Portrait_Top:
{
off_y = -frame.size.height;
on_y = 0.0f;
}
break;
case kBanner_Portrait_Bottom:
{
off_y = s.height;
on_y = s.height-frame.size.height;
}
break;
case kBanner_Landscape_Top:
{
off_y = -frame.size.height;
on_y = 0.0f;
}
break;
case kBanner_Landscape_Bottom:
{
off_y = s.height;
on_y = s.height-frame.size.height;
}
break;
default:
break;
}
frame.origin.y = off_y;
frame.origin.x = off_x;
mBannerView.frame = frame;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
frame = mBannerView.frame;
frame.origin.x = on_x;
frame.origin.y = on_y;
mBannerView.frame = frame;
[UIView commitAnimations];
}
-(void)showBannerView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = on_y;
frame.origin.x = on_x;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
}
-(void)hideBannerView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = off_y;
frame.origin.x = off_x;
}
completion:^(BOOL finished)
{
}];
}
}
-(void)dismissAdView
{
if (mBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGRect frame = mBannerView.frame;
frame.origin.y = off_y;
frame.origin.x = off_x;
mBannerView.frame = frame;
}
completion:^(BOOL finished)
{
[mBannerView setDelegate:nil];
[mBannerView removeFromSuperview];
mBannerView = nil;
}];
}
}
#导入“gadbanerview.h”
typedef枚举_bannerType
{
kBanner_肖像_顶部,
kBanner_纵向_底部,
kBanner_横向_顶部,
kBanner_横向_底部,
}CocosBannerType;
#定义横幅\u类型kBanner\u横向\u底部//根据需要更改此设置
@界面MyMain菜单:CCLayer
{
GADBannerView*mBannerView;
CocosBannerType-mBannerType;
浮动在x上、y上、x下、y下;
}
@实现MyMain菜单
-(void)onEnter
{
[超级合一];
[自创AdMobads];
}
-(无效)onExit
{
[自我否定];
[超级脱欧];
}
-(void)createAdmobAds
{
mBannerType=横幅类型;
AppController*app=(AppController*)[[UIApplication sharedApplication]委托];
//在屏幕底部创建标准尺寸的视图。
//可用的AdSize常量在gadaSize.h中进行了解释。
如果(mBannerType非常感谢,这对我帮助很大!我现在将尝试实现。有很多!!@Guru-在您的代码中,您指的是AppController。这是什么类?这是您的RootViewController吗?我正在努力让它工作。另外,navController似乎不是UIViewController的一部分。您是指navigationController吗?是的,在cocos2d AppController=AppDelegate中。您可以使用UIViewController而不是navController。仔细阅读后,我发现您的问题/答案适用于cocos2d版本2。经过一些调整后,我能够在版本1.1中实现这一点。但是,即使我指定了kBanner\u横向\u顶部,广告看起来似乎是纵向的。其他首先,广告大小已正确设置为kGADAdSizeSmartBannerLandscape,但由于它显示在设备的窄侧,因此您无法与它交互。如果我将广告大小更改为kGADAdSizeBanner,则可以与广告交互。但是,如果我打开广告然后关闭它,我的cocos2d视图将切换为纵向。有什么想法吗?我想它的问题是w对于CGSize s,仅使用视图控制器即可在COCOS2D1.0中打印s的值。