how to show admob in different scene

how to show admob in different scene
0.0 0


Hi, I’ve added admob in my game.

in, I added following code:

    bannerView_ = [[GADBannerView alloc] initWithAdSize:kGADAdSizeSmartBannerPortrait];
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    CGFloat screenWidth = screenRect.size.width;
    CGFloat screenHeight = screenRect.size.height;
    [bannerView_ setFrame:CGRectMake(0,
                                    // screenHeight-bannerView_.bounds.size.height,,
    bannerView_.adUnitID = @"myid";
    bannerView_.rootViewController = viewController;
    [viewController.view addSubview:bannerView_];
    [bannerView_ loadRequest:[GADRequest request]];

but this will result in displaying ad all the time.

so, just wondering, how to control of adding admob to different scene?


Got stuck on this for 2 days. Still have no idea.

I’ve implemented Admanager class in separate files to control it. But it doesn’t work at all.


so, here is what i’ve tried:

I created a AdBridge class:

namespace ls{
    class AdBridge: public cocos2d::CCObject{
        static cocos2d::CCScene* scene();
        virtual bool init();
        void showAddAtTop();
        void showAddAtBottom();


here is the implementation:

void ls::AdBridge::showAddAtTop(){
    [AdBridgemanager showAddAtTop];

void ls::AdBridge::showAddAtBottom(){
    [AdBridgemanager showAddAtBottom];

bool ls::AdBridge::init(){
    bool bRef = false;
    do {
        cocos2d::CCLog("AdBridge init ...");
        bRef = true;
    } while (0);
    return bRef;

then I created AdBridgeManager:

@implementation AdBridgeManager

+ (void) showAddAtTop{
    if(view && size.width>0){
        [view setFrame:CGRectMake(0, -13, 320, 50)];


+ (void) showAddAtBottom{
      if(view && size.width>0){
        [view setFrame:CGRectMake(0, size.height-50, 320, 50)];

so, this is what I have done…

Then I bind it to JS.

then in the scene, I called :

 var admanager= new ls.AdBridgeManager();

it suppose to work and show ad at bottom…

I did same thing for binding gamecenter and that worked.

But this ad banner always shows on top and never changed.

Is there anyone who can help me out this?

I guess i just used the wrong way to change the banner position.



You can have a look at:
User ‘getarobo’ posted quite a nice code that shows how to add AdMob to his game and hide/display it whenever you want.
Maybe this can help you also with the bottom/top positioning problem!