我正在開發一款使用cocos2d框架的2D遊戲,在此遊戲中,我使用admob作廣告,在某些課程中並非在所有課程中,但admob橫幅在每個課程中都是可見的,也會崩潰。Admob橫幅未從超級視圖中移除
我不明白admob橫幅是如何出現在每個類中的,事實上我沒有在Rootviewcontroller類中聲明。任何一個可以建議我如何向AdMob在cocos2d遊戲整合,我想特別班AdMob聯播旗幟不是每一個類, 我使用最新的谷歌AdMob SDK的,我的代碼如下:提前
感謝
`
-(void)AdMob{
NSLog(@"ADMOB");
CGSize winSize = [[CCDirector sharedDirector]winSize];
// Create a view of the standard size at the bottom of the screen.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(size.width/2-364,
size.height -
GAD_SIZE_728x90.height,
GAD_SIZE_728x90.width,
GAD_SIZE_728x90.height)];
}
else { // It's an iPhone
bannerView_ = [[GADBannerView alloc]
initWithFrame:CGRectMake(size.width/2-160,
size.height -
GAD_SIZE_320x50.height,
GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height)];
}
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
bannerView_.adUnitID [email protected]"a15062384653c9e";
}
else {
bannerView_.adUnitID [email protected]"a15062392a0aa0a";
}
bannerView_.rootViewController = self;
[[[CCDirector sharedDirector]openGLView]addSubview:bannerView_];
[bannerView_ loadRequest:[GADRequest request]];
GADRequest *request = [[GADRequest alloc] init];
request.testing = [NSArray arrayWithObjects:
GAD_SIMULATOR_ID, nil]; // Simulator
[bannerView_ loadRequest:request];
}
//best practice for removing the barnnerView_
-(void)removeSubviews{
NSArray* subviews = [[CCDirector sharedDirector]openGLView].subviews;
for (id SUB in subviews){
[(UIView*)SUB removeFromSuperview];
[SUB release];
}
NSLog(@"remove from view");
}
//this makes the refreshTimer count
-(void)targetMethod:(NSTimer *)theTimer{
//INCREASE OF THE TIMER AND SECONDS
elapsedTime++;
seconds++;
//INCREASE OF THE MINUTOS EACH 60 SECONDS
if (seconds>=60) {
seconds=0; minutes++;
[self removeSubviews];
[self AdMob];
}
NSLog(@"TIME: %02d:%02d", minutes, seconds);
}
`
用我更新的代碼在cocos2d 2.0,一切工作正常。 – Guru