I would like to know, how can I add a admob banner in cocos2d view?
This is my class
public class TitleScreen extends CCLayer{
private ScreenBackground background;
private ScreenBackground background2;
/**
* Intância do Player
*/
private MakeEnemyAnimation enemy;
private CCLayer enemyLayer;
public CCScene scene(){
CCScene scene = CCScene.node();
scene.addChild(this);
return scene;
}
public TitleScreen(Context context){
this.background = new ScreenBackground(Assets.BACKGROUND);
this.background.setPosition(
screenResolution(CGPoint.ccp(
screenWidth() / 2.0f,
screenHeight() / 2.0f
)));
this.addChild(this.background);
this.enemyLayer = CCLayer.node();
this.enemy = new MakeEnemyAnimation();
this.enemyLayer.addChild(this.enemy);
this.addChild(this.enemyLayer);
CCSprite title = CCSprite.sprite(Assets.GAMETITLE);
title.setPosition(screenResolution(
CGPoint.ccp( screenWidth() / 2 , screenHeight() - 70)));
title.setScaleX((float) 0.85);
title.setScaleY((float) 0.9);
this.addChild(title);
MenuButtons menuLayer = new MenuButtons(context);
this.addChild(menuLayer);
}
}
And that is the admob code
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
AdRequest adRequest = new AdRequest.Builder().build();
AdView adView = new AdView(context);
adView.setAdUnitId(MY_AD_UNIT_ID);
adView.loadAd(adRequest);
layout.addView(adView);
I'm already trying to do this over a week. I've tried many different ways but nothing works.
From this Post : put in onstart method.
LinearLayout.LayoutParams adParams = new LinearLayout.LayoutParams(
getWindowManager().getDefaultDisplay().getWidth(),
getWindowManager().getDefaultDisplay().getHeight()+getWindowManager().getDefaultDisplay().getHeight()-50);
adView = new AdView(SimpleGame.this, AdSize.BANNER, "your Ad ID");
adView.setAdListener(SimpleGame.this);
AdRequest request = new AdRequest();
request.addTestDevice(AdRequest.TEST_EMULATOR);
adView.loadAd(request);
CCDirector.sharedDirector().getActivity().addContentView(adView,adParams);