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 9115651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:28:57+00:00 2026-06-17T04:28:57+00:00

Does anybody know how to make work admob in cocos 2d v2, all the

  • 0

Does anybody know how to make work admob in cocos 2d v2, all the documentation is based in a view root controller and cocos2d 2 go just in another way.

The only documentation I found was this: Working-with-admob-and-cocos2d but its a little poor for a newbie like me. If anyone can help me I appreciate too much!!

  • 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-17T04:28:59+00:00Added an answer on June 17, 2026 at 4:28 am

    Here is my working admob cocos2d code: Copy createAdmobAds, showBannerView, hideBannerView and dismissAdView to your class.

    Here is Cocos2d 3.0 Admob Sample , for Cocos2d 2.0 check below

    #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;
    
             }];
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

does anybody know, how to make jQuery work in ckeditor plugin ? I created
Does anybody know of a comprehensive library to make SVG work with IE (7
Does anybody know how to make a custom BCL work with the stock CLR
Does anybody know if there is a way to make autocompletion work in MySQL
does anybody know how to make EJBTimers persistent not in filesystem, but in selected
Does anybody know a way to make the axis fixed on a CPTXYGraph when
In Oracle, this returns 03/01/2010. That does not make sense to me. Anybody know
does anybody know how to insert code into lyx? just like what is available
Does anybody know how to make the text that appears in the following li
Does anybody know why this function, when passed an invalid date (e.g. timestamp) to

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.