cocos2dx-3.1 接入多盟廣告sdk+Android (2)

來源:互聯網
上載者:User

標籤:win32   ccm   pre   dir   one   macros   title   roi   direct   

       上篇,把基本工作做完了,接下來,在C++下加入代碼。

      1、開啟win32下的project,加入一個類。DomobAd。代碼例如以下,


<pre name="code" class="cpp">#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)#include <jni.h>#include "platform/android/jni/JniHelper.h"//#include <android/log.h>#include "cocos2d.h"#endifusing namespace cocos2d;class DomobAd{public:DomobAd();virtual ~DomobAd();static void showInterstitial();/*static void initInterstitial();static void showBanner();static void hideBanner();*/};

#include "DomobAd.h"DomobAd::DomobAd(){}DomobAd::~DomobAd(){}//void DomobAd::showBanner()//{//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //JniMethodInfo showBanner;//bool isHave = JniHelper::getStaticMethodInfo(showBanner, "org/cocos2dx/cpp/AppActivity", "showBannerStatic", "()V");//if (!isHave) {//CCLog("jni:showBannerStatic false");//}//else{////showBanner.env->CallStaticVoidMethod(showBanner.classID, showBanner.methodID);//}//#endif//}//void DomobAd::hideBanner()//{//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //JniMethodInfo hideBanner;//bool isHave = JniHelper::getStaticMethodInfo(hideBanner, "org/cocos2dx/cpp/AppActivity", "hideBannerStatic", "()V");//if (!isHave) {//CCLog("jni:hideBannerStatic false");//}//else{//CCLog("jni:hideBannerStatic true");////hideBanner.env->CallStaticVoidMethod(hideBanner.classID, hideBanner.methodID);//}//#endif//}void DomobAd::showInterstitial(){#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) JniMethodInfo showInterstitial;bool isHave = JniHelper::getStaticMethodInfo(showInterstitial, "org/cocos2dx/cpp/AppActivity", "showInterstitialStatic", "()V");if (!isHave) {CCLog("jni:showInterstitial false");}else{CCLog("jni:showInterstitial true");showInterstitial.env->CallStaticVoidMethod(showInterstitial.classID, showInterstitial.methodID);}#endif}//void DomobAd::initInterstitial()//{//#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) //JniMethodInfo initInterstitial;//bool isHave = JniHelper::getStaticMethodInfo(initInterstitial, "org/cocos2dx/cpp/AppActivity", "initInterstitialStatic", "()V");//if (!isHave) {//CCLog("jni:initInterstitial false");//}//else{//CCLog("jni:initInterstitial true");////initInterstitial.env->CallStaticVoidMethod(initInterstitial.classID, initInterstitial.methodID);//}//#endif//}

#ifndef __APPMACROS_H__#define __APPMACROS_H__#include "cocos2d.h"#define DESIGN_RESOLUTION_480X320    0#define DESIGN_RESOLUTION_1024X768   1#define DESIGN_RESOLUTION_2048X1536  2/* If you want to switch design resolution, change next line */#define TARGET_DESIGN_RESOLUTION_SIZE  DESIGN_RESOLUTION_480X320typedef struct tagResource{    cocos2d::CCSize size;    char directory[100];}Resource;static Resource smallResource  =  { cocos2d::CCSizeMake(480, 320),   "iphone" };static Resource mediumResource =  { cocos2d::CCSizeMake(1024, 768),  "ipad"   };static Resource largeResource  =  { cocos2d::CCSizeMake(2048, 1536), "ipadhd" };#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(480, 320);#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(1024, 768);#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)static cocos2d::CCSize designResolutionSize = cocos2d::CCSizeMake(2048, 1536);#else#error unknown target design resolution!#endif// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution#define TITLE_FONT_SIZE  (cocos2d::CCEGLView::sharedOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)#endif /* __APPMACROS_H__ */


</pre><pre name="code" class="cpp">
//在helloworldscene.cpp加入例如以下代碼就可以:
<pre name="code" class="cpp"> CCMenuItemLabel  * closeInterstital=CCMenuItemLabel::create(CCLabelTTF::create("showInterstital", "Helvetica", 40),this, menu_selector(HelloWorld::menuShowInterstitialCallback));

void HelloWorld::menuShowInterstitialCallback(cocos2d::CCObject* pSender){    DomobAd::showInterstitial();}

//JniHelper 類是cocos提供的。詳細使用方法:http://blog.csdn.net/luxiaoyu_sdc/article/details/15874505<a target=_blank href="http://blog.csdn.net/luxiaoyu_sdc/article/details/15874505">點擊開啟連結</a>
</pre><pre name="code" class="cpp" style="font-size: 13.3333339691162px;">下片再繼續


cocos2dx-3.1 接入多盟廣告sdk+Android (2)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.