Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:29:51+00:00 2026-06-12T18:29:51+00:00

I am developing one 2d game using cocos2d framework, in this game i am

  • 0

I am developing one 2d game using cocos2d framework, in this game i am using admob for advertising, in some classes not in all classes but admob banner is visible in every class and after some time game getting crash also.

I am not getting how admob banner is comes in every class in fact i have not declare in Rootviewcontroller class. can any one suggest me how to integrate Admob in cocos2d game, i want Admob banner in particular classes not in every class,
I am using latest google admob sdk, my code is below:

Thanks in advance

`

-(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 =@"a15062384653c9e";
}
else {
    bannerView_.adUnitID =@"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);
 }

`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:29:52+00:00Added an answer on June 12, 2026 at 6:29 pm

    UPDATES: Refer generalised answer here: Admob-banner-integration-in-cocos2d

    I hope already u got solution. If not then here is all code for Admob integration in cocos2D game.

     #define ENABLE_ADMOB 1
     //#define COCOS2D_2_0 1
    
    @interface MyMainMenu : CCLayer
    {
        #ifdef ENABLE_ADMOB
        GADBannerView *mBannerView;
        #endif
    }
    
    @implementation MyMainMenu
    
    -(void)onEnter
    {
        [super onEnter];
    
        #ifdef ENABLE_ADMOB
           #ifdef COCOS2D_2_0
             AppController *app =  (AppController*)[[UIApplication sharedApplication] delegate];    
           #else 
             AppDelegate* app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
           #endif
        mBannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
    
        // 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.
    
    
        //size
    
    
        #ifdef COCOS2D_2_0
        mBannerView.rootViewController = app.navController;
        [app.navController.view addSubview:mBannerView];
        #else 
        mBannerView.rootViewController = app.viewController;
        [app.viewController.view addSubview:mBannerView];
        #endif
    
        // Initiate a generic request to load it with an ad.
        [mBannerView loadRequest:[GADRequest request]];
    
        CGSize AdSize = kGADAdSizeBanner.size;
    
        CGRect frame = mBannerView.frame;
        frame.origin.y = -50.0f;
    
        #ifdef COCOS2D_2_0
        frame.origin.x = (app.navController.view.bounds.size.width - AdSize.width) / 2 ;
        #else
        frame.origin.x = (app.viewController.view.bounds.size.width - AdSize.width) / 2 ;
        #endif
    
        mBannerView.frame = frame;
    
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.5];
        [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
    
        frame = mBannerView.frame;
        frame.origin.y = 0.0f;
    
        mBannerView.frame = frame;
        [UIView commitAnimations];    
    
        #endif
    }
    
    -(void)showBannerView
    {
        if (mBannerView) 
        {
            [UIView animateWithDuration:0.5
                                  delay:0.1
                                options: UIViewAnimationCurveEaseOut
                             animations:^
             {
                 CGRect frame = mBannerView.frame;
                 frame.origin.y = 0.0f;
                 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 = -50.0f;
                 mBannerView.frame = frame;
             } 
                             completion:^(BOOL finished)
             {
             }];
        }
    
    }
    
    
    -(void)dismissAdView
    {
    #ifdef ENABLE_ADMOB
        if (mBannerView) 
        {
            [UIView animateWithDuration:0.5
                                  delay:0.1
                                options: UIViewAnimationCurveEaseOut
                             animations:^
             {
                 CGRect frame = mBannerView.frame;
                 frame.origin.y = -50.0f;
                 mBannerView.frame = frame;
             } 
                             completion:^(BOOL finished)
             {
                 [mBannerView setDelegate:nil];
                 [mBannerView removeFromSuperview];
                 mBannerView = nil;
    
             }];
        }
    #endif  
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing a puzzle game. This application I am using one drawable image
I am developing a puzzle game. This application I am using one drawable image
I am developing a little game (I'm using Play! framework ). In this game,
I am developing a game using Cocos2D for iOS. There are some scenes like
I'm facing some troubles with memory consumption while developing 2D game using libGDX. It's
I'm developing a game for iPhone and is pretty far along, but one thing
I'm developing a game for iPhone and is pretty far along, but one thing
HI to all, I am new in game developing part .Can any one help
I am a beginner in Android. I am developing one animated game in Activity(not
I am developing iPhone game application using one UIView and GraphicsContext. The belows are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.