Cocos2d-x 游戏中嵌入广告(mogo横幅)

Cocos2d-x 游戏中嵌入广告(mogo横幅),第1张

概述转载请注明出处:http://www.voidcn.com/article/p-omllqquw-dy.html DEMO下载地址:http://download.csdn.net/detail/oyangyufu/7578451 在经过国内的几个广告平台尝试,最终选择芒果广告,有几个优点:SDK更新较快,支持cocos2d-x3.0,平台还聚合了国内主流广告平台,下载相应的SDK也可加载到工程中

转载请注明出处:http://www.jb51.cc/article/p-omllqquw-dy.html

DEMO下载地址:http://download.csdn.net/detail/oyangyufu/7578451

在经过国内的几个广告平台尝试,最终选择芒果广告,有几个优点:SDK更新较快,支持cocos2d-x3.0,平台还聚合了国内主流广告平台,下载相应的SDK也可加载到工程中。

芒果横幅广告测试

1、将cocos2d-x项目导入到eclipse上

2、下载androID SDK cocos2d-x 版本,网址:http://my.adsmogo.com/Apps/Download,下载完名称为:Adsmogo_AndroID_Cocos2d-x_Demo.zip

3、解压后将jar包放入libs目录下,单击右键->Build Path->Add to Build Path

4、在AndroIDManifest.xml添加用户权限:

[cpp] view plain copy @H_403_33@ <uses-permissionandroID:name="androID.permission.INTERNET"/> <uses-permissionandroID:name="androID.permission.MODIFY_AUdio_SETTINGS"/> <uses-permissionandroID:name="androID.permission.INTERNET"/> <uses-permissionandroID:name="androID.permission.READ_EXTERNAL_STORAGE"/> <uses-permissionandroID:name="androID.permission.READ_PHONE_STATE"/> <uses-permissionandroID:name="androID.permission.ACCESS_COARSE_LOCATION"/> <uses-permissionandroID:name="androID.permission.ACCESS_FINE_LOCATION"/> <uses-permissionandroID:name="androID.permission.ACCESS_NETWORK_STATE"/> <uses-permissionandroID:name="androID.permission.ACCESS_LOCATION_EXTRA_COMMANDS"/> <uses-permissionandroID:name="androID.permission.CALL_PHONE"/> <uses-permissionandroID:name="androID.permission.WRITE_EXTERNAL_STORAGE"/> <uses-permissionandroID:name="androID.permission.ACCESS_WIFI_STATE"/> <uses-permissionandroID:name="androID.permission.CHANGE_WIFI_STATE"/> <uses-permissionandroID:name="androID.permission.VIBRATE"/> <uses-permissionandroID:name="androID.permission.RECORD_AUdio"/> <uses-permissionandroID:name="androID.permission.GET_TASKS"/> <uses-permissionandroID:name="androID.permission.CAMERA"/> <uses-permissionandroID:name="androID.permission.RECEIVE_BOOT_COMPLETED"/> <uses-permissionandroID:name="androID.permission.CHANGE_CONfigURATION"></uses-permission>


5、声明广告平台Activity, 代码到AndroIDMainfest.xml文件中的application标签中

<preclass="cpp"name="code"><activity androID:name="com.adsmogo.advIEw.AdsmogoWebVIEw" androID:configChanges="orIEntation|keyboardHIDden|screenSize" androID:label="@string/app_name"> </activity> <!--注册Service,自主广告与交换广告的应用下载功能所需--> <serviceandroID:name="com.adsmogo.controller.service.UpdateService" androID:exported="true" androID:process=":remote"/> <!--注册Service,安装应用所用--> <serviceandroID:name="com.adsmogo.controller.service.CountService" androID:process=":remote"/>


6、在主Activity类中,添加横幅广告

publicclassTestextendsCocos2dxActivity{ privatestaticHandlerhandler; staticrelativeLayoutbannerLayout; privateAdsmogolayoutadVIEw; protectedvoIDonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); bannerLayout=newrelativeLayout(this); relativeLayout.LayoutParamsparentLayputParams=newrelativeLayout.LayoutParams( relativeLayout.LayoutParams.FILL_PARENT, relativeLayout.LayoutParams.FILL_PARENT); this.addContentVIEw(bannerLayout,parentLayputParams); /** @H_433_404@*初始化全插屏对象 *初始化之前必须设置默认的AppKey和Activity */ AdsmogoInterstitialManager.setDefaultinitAppKey("93535c6092f543e8a257ee435a69da06"); AdsmogoInterstitialManager.setInitactivity(Test. AdsmogoInterstitialManager.shareInstance() .initDefaultInterstitial(); .defaultInterstitial() .setAdsmogoInterstitialListener(newAdsmogoInterstitialListener(){ @OverrIDe voIDonShowInterstitialScreen(Stringarg0){ //Todoauto-generatedmethodstub Log.v("mogoCocos2dxDemo","onShowInterstitialScreen"); } publicbooleanonInterstitialStaleDated(Stringarg0){ "onInterstitialStaleDated"); returnfalse; } @OverrIDe voIDonInterstitialRealClickAd(Stringarg0){ //Todoauto-generatedmethodstub Log.v("mogoCocos2dxDemo","onInterstitialRealClickAd"); publicVIEwonInterstitialGetVIEw(){ "onInterstitialGetVIEw"); returnbannerLayout; voIDonInterstitialCloseAd(booleanarg0){ "onInterstitialCloseAd"); publicbooleanonInterstitialClickClosebutton(){ "onInterstitialClickClosebutton"); voIDonInterstitialClickAd(Stringarg0){ "onInterstitialClickAd"); publicClassgetCustomEvemtPlatformAdapterClass( AdsmogoCustomEventPlatformEnumarg0){ returnnull; }); // handler=newHandler(){ voIDhandleMessage(Messagemsg){ switch(msg.what){ case0: //展示Banner if(bannerLayout.getChildCount()==0){ adVIEw=newAdsmogolayout(Test.this, "46184ad32a0c417887cb433203b11403"); adVIEw.setAdsmogoListener(newAdsmogoListener(){ voIDonRequestAd(Stringarg0){ "onRequestAd"); voIDonReceiveAd(VIEwGrouparg0,Stringarg1){ "onReceiveAd"); voIDonRealClickAd(){ "onRealClickAd"); voIDonFailedReceiveAd(){ "onFailedReceiveAd"); voIDonClosemogoDialog(){ "onClosemogoDialog"); publicbooleanonCloseAd(){ voIDonClickAd(Stringarg0){ "onClickAd"); relativeLayout.LayoutParamslayoutParams= relativeLayout.LayoutParams.WRAP_CONTENT); layoutParams.addRule( relativeLayout.AliGN_PARENT_BottOM, relativeLayout.TRUE); bannerLayout.addVIEw(adVIEw,layoutParams); break; case1: onClickHIDeShow(); break; case3: /** *进入展示时机 *当应用需要展示全屏广告调用interstitialShow(booleanisWait); *通知SDK进入展示时机,SDK会竭尽全力展示出广告,当然由于网络等问题不能立即展示 *广告的,您可以通过参数isWait来控制授权SDK在获得到广告后立即展示广告。 */ AdsmogoInterstitialManager.shareInstance() .defaultInterstitial().interstitialShow(true); case4: Test.this.finish(); case5: *退出展示时机 *如果您之前进入了展示时机,并且isWait参数设置为YES,那么在需要取消等待广告展示的 *时候调用方法interstitialCancel();来通知SDK .defaultInterstitial().interstitialCancel(); }; publicCocos2dxGLSurfaceVIEwonCreateVIEw(){ Cocos2dxGLSurfaceVIEwglSurfaceVIEw=newCocos2dxGLSurfaceVIEw(this); //Testshouldcreatestencilbuffer glSurfaceVIEw.setEGLConfigChooser(5,6,5,16,8); returnglSurfaceVIEw; //显示横屏广告 staticvoIDshowBannerStatic(){ Messagemsg=handler.obtainMessage(); msg.what=0; handler.sendMessage(msg); //关闭横屏广告 voIDhIDeBannerStatic(){ msg.what=1; voIDshowInterstitialStatic(){ msg.what=3; voIDclose(){ Messagemsg=handler.obtainMessage(); msg.what=4; handler.sendMessage(msg); voIDcloseInterstitial(){ msg.what=5; static{ System.loadlibrary("cocos2dcpp"); voIDonClickHIDeShow(){ if(adVIEw!=null){ adVIEw.setVisibility(adVIEw.getVisibility()==VIEw.VISIBLE?VIEw.GONE :VIEw.VISIBLE); }


7、CCP程序中jni调用java函数,显示广告

定义方法:

#include"mogOAd.h" mogOAd::mogOAd(){} mogOAd::~mogOAd(){} voIDmogOAd::showBanner() { #if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID) JniMethodInfoshowBanner; boolisHave=JniHelper::getStaticmethodInfo(showBanner,"com/cocos2dx/org/Test","showBannerStatic","()V"); if(!isHave){ cclog("jni:showBannerStaticfalse"); }else{ showBanner.env->CallStaticVoIDMethod(showBanner.classID,showBanner.methodID); #endif voIDmogOAd::hIDeBanner() { #if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID) JniMethodInfohIDeBanner; boolisHave=JniHelper::getStaticmethodInfo(hIDeBanner,"hIDeBannerStatic","()V"); if(!isHave){ cclog("jni:hIDeBannerStaticfalse"); }else{ cclog("jni:hIDeBannerStatictrue"); hIDeBanner.env->CallStaticVoIDMethod(hIDeBanner.classID,hIDeBanner.methodID); voIDmogOAd::showInterstitial() JniMethodInfoshowInterstitial; boolisHave=JniHelper::getStaticmethodInfo(showInterstitial,"showInterstitialStatic",248)"> cclog("jni:hIDeBannerStaticfalse"); cclog("jni:hIDeBannerStatictrue"); showInterstitial.env->CallStaticVoIDMethod(showInterstitial.classID,showInterstitial.methodID); #endif voIDmogOAd::close() "org/cocos2dx/cpp/AdsmogoCoCos2dx","close",153); Font-weight:bold; background-color:inherit">voIDmogOAd::closeInterstitial() JniMethodInfocloseInterstitial; boolisHave=JniHelper::getStaticmethodInfo(closeInterstitial,"closeInterstitial",248)"> closeInterstitial.env->CallStaticVoIDMethod(closeInterstitial.classID,closeInterstitial.methodID);
8、创建菜单按钮,点击显示广告
CCSizewinSize=CCDirector::sharedDirector()->getWinSize(); CcmenuItemLabel*bannerLable=CcmenuItemLabel::create(cclabelTTF::create("showbanner","Helvetica",30),bannerLable->setposition(ccp(winSize.wIDth-200,winSize.height-80)); voIDHelloWorld::menuCloseCallback(CCObject*pSender)
mogOAd::close(); voIDHelloWorld::menuBannerCallback(CCObject*pSender){ mogOAd::showBanner(); voIDHelloWorld::menuRequestInterstitialCallback(CCObject*pSender){ mogOAd::hIDeBanner(); voIDHelloWorld::menushowInterstitialCallback(CCObject*pSender){ mogOAd::showInterstitial(); voIDHelloWorld::menucloseInterstitalCallback(CCObject*pSender){ mogOAd::closeInterstitial(); }
9、效果图

总结

以上是内存溢出为你收集整理的Cocos2d-x 游戏中嵌入广告(mogo横幅)全部内容,希望文章能够帮你解决Cocos2d-x 游戏中嵌入广告(mogo横幅)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1069098.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存