gpt4 book ai didi

安卓-admob + cocos2d

转载 作者:行者123 更新时间:2023-11-30 03:04:02 25 4
gpt4 key购买 nike

我想知道,如何在 cocos2d View 中添加 admob 横幅?

这是我的类(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);

}
}

那是admob代码

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);

我已经尝试了一个多星期。我尝试了很多不同的方法,但没有任何效果。

最佳答案

来自这个 Post : 放入 onstart 方法。

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);

关于安卓-admob + cocos2d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116333/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com