对了cocos2d-X的插页式广告 [英] Interstitial ads for cocos2d-x
问题描述
我是新来的Cocos2D-X。我公司开发的X code进行游戏使用的cocos2d-x和我把它移植到Android。
我想比赛结束&放大器后使用插页广告;还当我重播。它应该显示在游戏画面上。我使用下面的code,以显示广告。但他们显示在开始比赛前,当我重播的比赛,他们从不显示。
在我退出并重新启动广告开始一个新游戏之前显示一次。任何人都可以请帮我找到解决办法?
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 间质性=新在InterstitialAd(本);
interstitial.setAdUnitId(***********); AdRequest中AdRequest中=新AdRequest.Builder()建立()。
interstitial.loadAd(AdRequest中);
interstitial.setAdListener(新AdListener的(){
公共无效onAdLoaded(){
displayInterstitial();
}
});
}公共无效displayInterstitial(){
如果(interstitial.isLoaded()){
interstitial.show();
}
}
添加上@Xaver Kapeller的回答是:因为这是一个cocos2d的-X的游戏,你将不得不从C调用Java方法++。这可通过JNI呼叫来完成。有上了cocos2d-X论坛,许多这样的例子(特别是与在浏览器中打开链接,但总的原则是一样的),例如:的链接
I am new to cocos2d-x. I developed a game in xcode using cocos2d-x and I ported it to Android. I want to use interstitial ads after game ends & also when I replay. It should display on the game over screen. I am using the following code to display the ads. But they are displayed before starting the game and they are never displayed when I replay the game.
Once I quit and restart the ad is shown once before starting a new game. Can anyone please help me to find the solution?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("***********");
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener() {
public void onAdLoaded() {
displayInterstitial();
}
});
}
public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
Adding on @Xaver Kapeller's answer : as this is a cocos2d-x game, you will have to call a java method from C++. This can be done via JNI calls. There are many examples of this on cocos2d-x forums (especially related to opening links in browser, but the general rule is the same), for example : link
这篇关于对了cocos2d-X的插页式广告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!