在cocos2d-x中如何嵌入百度的插屏广告

前端之家收集整理的这篇文章主要介绍了在cocos2d-x中如何嵌入百度的插屏广告前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

DEMO下载:http://download.csdn.net/detail/oyangyufu/7652803

演示的效果请看这里:http://pan.baidu.com/s/1o6oit9w

1、声明Activity

  1. <!--声明百度的Activity-->
  2. <Meta-dataandroid:name="BaiduMobAd_APP_ID"android:value="debug"/>
  3. <Meta-dataandroid:name="BaiduMobAd_APP_SEC"android:value="debug"/>
  4. <activityandroid:name="com.baidu.mobads.AppActivity"
  5. android:configChanges="keyboard|keyboardHidden|orientation"/>


2、在主Activity类中,初始广告对象

  1. interAd=newInterstitialAd(this);
  2. interAd.setListener(newInterstitialAdListener(){
  3. @Override
  4. publicvoidonAdClick(InterstitialAdarg0){
  5. Log.i("InterstitialAd","onAdClick");
  6. }
  7. @Override
  8. publicvoidonAdDismissed(){
  9. Log.i("InterstitialAd","onAdDismissed");
  10. interAd.loadAd();
  11. }
  12. @Override
  13. publicvoidonAdFailed(Stringarg0){
  14. Log.i("InterstitialAd","onAdFailed");
  15. }
  16. @Override
  17. publicvoidonAdPresent(){
  18. Log.i("InterstitialAd","onAdPresent");
  19. }
  20. @Override
  21. publicvoidonAdReady(){
  22. Log.i("InterstitialAd","onAdReady");
  23. }
  24. });
  25. //加载广告
  26. interAd.loadAd();

3、显示广告

  1. handler=newHandler(){
  2. @Override
  3. publicvoidhandleMessage(Messagemsg){
  4. //TODOAuto-generatedmethodstub
  5. switch(msg.what){
  6. case3:
  7. //publicvoidonClick(Viewarg0){
  8. if(interAd.isAdReady()){//读取是否成功
  9. Log.i("InterstitialAd","showAd");
  10. interAd.showAd(Test.this);//显示
  11. }else{
  12. interAd.loadAd();
  13. Log.i("InterstitialAd","loadAd...");
  14. }
  15. break;
  16. }
  17. }
  18. };


4、定义静态函数,用于cpp调用

  1. publicstaticvoidshowInterstitialStatic(){
  2. Messagemsg=handler.obtainMessage();
  3. msg.what=3;
  4. handler.sendMessage(msg);
  5. }

5、效果图,点show

原文链接:https://www.f2er.com/cocos2dx/344833.html

猜你在找的Cocos2d-x相关文章