cocos2dx-3.1 access to multi-League advertising Sdk+android (2)

Source: Internet
Author: User

In the previous article, the basic work is done, next, in C + + to add code.

1. Open Project under Win32 and add a class. Domobad. Code such as the following,


<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::D Omobad () {}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-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, +), "iphone"};static Resource Mediumresource = {Cocos2d::ccsizemake (1024x768, 768), "ipad"};static Resource Largeresource = {Cocos2d::ccsizemake (2048, 1536), "Ipadh D "}; #if (target_design_resolution_size = = design_resolution_480x320) static Cocos2d::ccsize designresolutionsize = Cocos2d::ccsizemake (480), #elif (target_design_resolution_size = = design_resolution_1024x768) static cocos2d:: Ccsize designresolutionsize = Cocos2d::ccsizemake (1024x768, 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 is designed for small resolution, so we should change it to fit for current design resolution#define TITL E_font_size (Cocos2d::cceglview::sharedopenglview ()->getdesignresolutionsize (). Width/ SmallResource.size.width *) #endif/* __appmacros_h__ */

</pre><pre name= "code" class= "CPP" >
Add the following code to the Helloworldscene.cpp:
<pre name= "code" class= "CPP" > Ccmenuitemlabel  * closeinterstital=ccmenuitemlabel::create (Cclabelttf:: Create ("Showinterstital", "Helvetica", +), this, Menu_selector (Helloworld::menushowinterstitialcallback));

void Helloworld::menushowinterstitialcallback (cocos2d::ccobject* psender) {    domobad::showinterstitial ();}

The Jnihelper class is provided by Cocos. Detailed use method: Http://blog.csdn.net/luxiaoyu_sdc/article/details/15874505<a target=_blank href= "http://blog.csdn.net/ luxiaoyu_sdc/article/details/15874505 "> Click to open Link </a>
</pre><pre name= "code" class= "CPP" style= "FONT-SIZE:13.3333339691162PX;" > next film to continue

cocos2dx-3.1 access to multi-League advertising Sdk+android (2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.