Search code examples
iphonecocos2d-iphoneadmobiadads

How to put a permanent view (for ads) in a cocos2d project


I have a cocos2d project with some scenes (home scene, level selection scene, game scene, credit scene and so on) and I have an ad banner view in every scene.

I'm creating the banner view in every scene but I don't like this (I want the ad stay in place until it reloads by itself).

So how can I have the ads always on screen and scenes changes without reloading the ad view at every scene change?

Is that possibile?


Solution

  • Yes, simply add the banner view to:

    [[CCDirector sharedDirector].openGLView addSubview:bannerView];
    

    This is of course assuming that your bannerView is a UIKit view, as most banners are. If your banner view is actually a sprite or other cocos2d node, you have little choice other than keep doing what you already do. The only way to ensure the view stays permanent is to modify CCDirector, specifically the replaceScene method would have to remove the view from the currentscene and add it back in to the next scene.