码迷,mamicode.com
首页 > 其他好文 > 详细

Cocos2d-x 游戏中嵌入广告(百度插屏)

时间:2014-07-06 00:25:29      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:cocos2dx   广告   广告平台   

1、声明Activity

 <!-- 声明百度的Activity -->
		<meta-data android:name="BaiduMobAd_APP_ID" android:value="debug" /> 
		<meta-data android:name="BaiduMobAd_APP_SEC" android:value="debug" />
		<activity android:name="com.baidu.mobads.AppActivity" 
		    android:configChanges="keyboard|keyboardHidden|orientation" />


 

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

interAd=new InterstitialAd(this);
		interAd.setListener(new InterstitialAdListener(){

			@Override
			public void onAdClick(InterstitialAd arg0) {
				Log.i("InterstitialAd","onAdClick");
			}

			@Override
			public void onAdDismissed() {
				Log.i("InterstitialAd","onAdDismissed");
				interAd.loadAd();
			}

			@Override
			public void onAdFailed(String arg0) {
				Log.i("InterstitialAd","onAdFailed");
			}

			@Override
			public void onAdPresent() {
				Log.i("InterstitialAd","onAdPresent");
			}

			@Override
			public void onAdReady() {
				Log.i("InterstitialAd","onAdReady");
			}
			
		});
		//加载广告
		interAd.loadAd();

3、显示广告

handler = new Handler(){
		
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				switch (msg.what) {
				case 3:
							
						//public void onClick( View arg0 ) {
							if(interAd.isAdReady()){//读取是否成功
								Log.i("InterstitialAd","showAd");
								interAd.showAd(Test.this);//显示
							}else{
								interAd.loadAd();
								Log.i("InterstitialAd","loadAd...");
							}

					break;
				}
			}
		};


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

public static void showInterstitialStatic() {
		Message msg = handler.obtainMessage();
		msg.what = 3;
		handler.sendMessage(msg);
	}


5、效果图,点show

bubuko.com,布布扣


 

Cocos2d-x 游戏中嵌入广告(百度插屏),布布扣,bubuko.com

Cocos2d-x 游戏中嵌入广告(百度插屏)

标签:cocos2dx   广告   广告平台   

原文地址:http://blog.csdn.net/oyangyufu/article/details/36902385

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!