Cocos2d-x, as an excellent cross-platform game engine, has been used by more and more developers, while the use of share components in the game to effectively provide user stickiness, through the sharing of reflux to improve the app installs, but currently on the market can be used in the cocos2d-x environment of the share plugin is not many, Developers can only package their native sharing SDK themselves, and the alliance launched the Cocos2d-x share component in the previous period to help developers quickly integrate. Friends also put the components of the source code on GitHub, there are good ideas can also be directly on GitHub modification (PS. On GitHub on the bug can get friends of the small prizes), the same can also learn from the source, the help of developers is still very large.
Integration Preparation:
First, a brief introduction to the composition of the component compression package
-
Cocos2dx
-
Realize cross-platform sharing function in Cocos2d-x, copy to classes folder of your project;
-
Platforms
-
Native Android and iOS social Component SDK, which requires you to copy libraries and resources to the corresponding platform project;
-
Doc
-
Integrated documentation of the components;
-
umeng_cocos2dx_demo_v1.0
-
Android part of the demo file can be installed on the phone to see a simple sharing effect and style
Cocos2d-x is a cross-platform engine, but for Android and iOS platforms, there are some differences in how the integration works, and here are some of the different aspects of Android and iOS platform integration, and then focus on the common cross-platform sections.
Android Platform Integration steps:Step One:
Download the Cocos2d-x component () and add the jar package to the build path path, adding the Res resource folder to your project's corresponding resource file. Copy the COM folder under the Platforms/android/controller directory to the SRC directory of your Cocos2d-x project's Android platform, and local_src_ in Jni/android.mk Under Files, add the following configuration (note the format, otherwise compile error):
.. /.. /classes/cocos2dx/android/CCUMSocialController.cpp . /.. /classes/cocos2dx/sharebutton/UMShareButton.cpp. /.. /classes/cocos2dx/common/ccumsocialsdk.cpp
Step Two:
Under the OnCreate method of the Cocos2dxactivity subclass, add the following code to complete the initialization step
// This is the cocos2dxactivity type, and the parameter 2 is a descriptor that can be modified arbitrarily. CCUMSOCIALCONTROLLER.INITSOCIALSDK (This, "Com.umeng.social.share");
Step Three:
Overwrite the Onactivityresult method of the Cocos2dxactivity subclass in the code to implement the callback method. Add the following code to the Onactivityresult:
// Authorization Callbacks Ccumsocialcontroller.onactivityresult (Requestcode, ResultCode, data); Super. Onactivityresult (Requestcode, ResultCode, data);
iOS platform integration steps:Step One:
Unzip the SDK package, drag the Platforms/ios folder and the Cocos2dx folder into the project directory, and delete the Cocos2dx/android folder, which should be added after this effect:
Step Two:
Add the framework required by the system
Security.framework//for system encryption processingLibiconv.dylib//QQ Connected library fileSystemconfiguration.framework//the framework required for QQ interconnectionCoregraphics.framework//the framework required for QQ interconnectionSocial.framework//share the framework required by the component, and if you don't use Twitter, you don't needLibsqlite3.dylib//the framework required for QQ interconnectionLibstdc++.dylib//library files for C + +Coretelephony.framework//the framework required for QQ interconnectionLibz.dylib//the framework required for QQ interconnectionAccounts.framework//the framework that the system needs, and if you don't use Twitter, you don't need
Step Three:
Implement a callback method for the system by adding the following code to the appcontroller.mm file in the iOS folder in the Xcode project:
#import " UMSocial.h "-(BOOL) Application: (UIApplication *) application OpenURL: (nsurl *) URL sourceapplication: (NSString *) sourceapplication annotation: (ID) annotation{ return [umsocialsnsservice Handleopenurl:url];}
Once you have completed the preparation, you can begin the formal sharing process, which offers a variety of sharing styles, energetic developers can use the underlying interface, can be completely free to customize the sharing interface and style, but I believe most developers use third-party plug-ins to save energy, So here are just a few ways to use the default sharing interface, and developers with more needs can explore their own custom interface.
Step One: Join the system required header file
//Authorization Callbacks#include"cocos2dx/common/ccumsocialsdk.h"#include"Cocos2dx/sharebutton/umsharebutton.h"//Use the Allies command spaceusing_ns_um_social;// ...... Code omitted//HelloWorld as a subclass of Cocos2d::cclayerBOOLHelloworld::init () {////////////////////////////// //1. Super init First if( !Cclayer::init ()) { return false; }}Step Two: Create a share button
// Create a share button, parameter 1 is the normal picture of the button, parameter 2 is the picture when the button is selected, Parameter 3 is au appkey, parameter 4 is the share callback Umsharebutton *sharebutton = umsharebutton::create ("sharenormal.png"," Shareselected.png " your friend au appkey", Share_selector (Sharecallback));
Step three: Set up sharing platform and content
//platform displayed on the Friends sharing panelvector* platforms =Newvector ();p latforms-push_back (SINA);p latforms-push_back (RENREN);p latforms-push_back (Douban);p latforms-push_back (QZONE);p latforms-push_back (QQ);//set up the platform shown on the Friends sharing panelSharebutton->setplatforms (platforms);//set up text sharing contentSharebutton->setsharecontent ("Umeng Social cocos2d-x SDK.") ;//set up images to share, images that support local images and URLs, but URL images must be in http://or https://StartSharebutton->setshareimage ("/sdcard/header.jpeg")//set the position of the buttonSharebutton->setposition (CCP ( Max, the)); //then the developer needs to add the button to the game scene.ccmenu* Pmenu =ccmenu::create (Sharebutton, NULL);p menu-setposition (Ccpointzero); This->addchild (Pmenu,1);//********************** setting platform information ***************************//ccumsocialsdk *sdk = Sharebutton->getsocialsdk ();//Sdk->setqqappidandappkey ("Set the app ID for QQ", "Appkey");//sdk->setweixinappid ("Settings and app ID for Friends Circle");//Sdk->setyixinappkey ("Set up an app ID for easy-to-believe and a friend circle");//Sdk->setlaiwangappinfo ("Set app ID for traffic and traffic",//"Set up the app key for traffic and traffic", "My App name");//sdk->setfacebookappid ("your Facebook AppID");//set user to click on a text to share when the user jumps to the target page, usually the app homepage or download page//Sdk->settargeturl ("http://www.umeng.com/social");//Open or Close log//sdk->setlogenable (true);//********************** END ***************************
Integration into this step is complete, if there is no exception, the following interface should appear, which indicates that you have successfully implemented the integration work.
Well, to here, the entire integration process is over, many people are more concerned about the difficulty of integration components, friends of June assessment feel, with a certain development of the basic research and development students can be in a day to complete the integration of the entire component, strong technology, Daniel, minutes to fix. Thank you for reading, hope to help everyone!
Component Download Portal: Http://dev.umeng.com/social/cocos2d-x/sdk-download
GitHub Portal: Http://github.com/umeng/umeng-social-for-cocos2d-x