我根据Admob的教程,新建一个cocos2dx的helloword项目,添加了除addon以外的文档,添加了framework,添加了ObjC,然后修改了rootViewController的h和mm,添加了相关代码如下:
h文件中:
@interface RootViewController : UIViewController {
GADBannerView *bannerView_;
}
mm文件中:
-
(void)viewDidload {
NSLog(@“viewDidload begin”);
;bannerView_=initWithAdSize:kGADAdSizeBanner];
bannerView_.adUnitID = 本人在admob获得的号码;
bannerView_.rootViewController=self;
;];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
} -
(void)dealloc {
;
;
}
在做完所有这些工作后,运行却只看到helloword的界面,而没有看到广告条。
输出结果为:
2014-06-02 15:04:28.884 Admobtest cocos2d: surface size: 960x640
Cocos2d:
cocos2d.x.version: 2.1rc0-x-2.1.4
cocos2d.x.compiled_with_profiler: false
cocos2d.x.compiled_with_gl_state_cache: true
gl.vendor: Apple Computer, Inc.
gl.renderer: Apple Software Renderer
gl.version: OpenGL ES 2.0 APPLE-9.4.3
gl.max_texture_size: 4096
gl.max_texture_units: 8
gl.max_samples_allowed: 4
gl.supports_PVRTC: true
gl.supports_NPOT: true
gl.supports_BGRA8888: false
gl.supports_discard_framebuffer: true
gl.supports_vertex_array_object: true
我下载了admob的示例程序,运行后是可以出现广告条的。
输出结果为:
2014-06-01 09:15:28.414 BannerExample To get test ads on this device, call: request.testDevices = ;
2014-06-01 09:15:28.972 BannerExample Google:HTML Google Mobile Ads SDK: You are currently using 6.5.1 of the SDK. A new version, 6.9.2, is available at http://goo.gl/Zc0BYt . Please consider updating your SDK to get the latest features and bug fixes
2014-06-01 09:15:29.053 BannerExample Received ad successfully
从输出结果来看helloworld并没有运行到admob的程序,因为viewDidload 中的NSLog(@“viewDidload begin”)没有被执行。
在对比了两者(示例程序和helloworld)之后,我发现除了admob要添加的那些文件外,示例程序是只有简单的4个文件:
BannerExampleAppDelegate.h,BannerExampleAppDelegate.m,BannerExampleViewController.h,BannerExampleViewController.m。
而helloword则有8个文件:
AppController.h,AppController.mm,RootViewController.h,RootViewController.mm,Appdelegate.h,Appdelefate.cpp,HelloworldScene.h,HelloworldScene.mm.
示例程序的运行应该是main->BannerExampleAppDelegate->BannerExampleViewController,而在网上查了一下,hello world的运行上应该是main->AppController->Appdelegate->HelloworldScene。
所以现在的困惑是:
1.怎么设定才能运行到RootViewController?
2.如何在不同的layer上绑定运行admob的广告条,比如只在游戏的主界面运行广告条,而在游戏选择界面、帮助界面等不运行?
3.如何设定广告条的大小和位置等?
因为网上都说地很简单,基本内容都和教程上说地一样。我现在地问题没找到相应地解答,所以在这里请大神解答,先谢谢啦!!