Cocos2dx-demo Demo Project: Part1

Source: Internet
Author: User

In this project, I am mainly used to accumulate and record my development experience in project development and learning practice using COCOS2DX engine. Every day of development tasks, to see what others share, always be able to reap the desirable things, to develop these desirable things on their own again, to further understand these, and in the future if you encounter similar development needs, I can quickly migrate to the development project. So I put the knowledge that I accumulate in my daily life through a demonstration project and show it. Because there is no Apple device, I do not have the conditions so I only do the development of the Android (related components are required to add the Android, iOS separately).

PART1: Friends League social sharing

Reasons for adding this component:

In the game development, if the social sharing element is added, the interactivity of the game will be greatly improved, which can provide a great help to improve the game retention. Each social networking site provides a shared API interface, and if you write a support interface for each social share individually, the task volume will be quite large. There is a need to have a market, friends of the Alliance provides social sharing of components, the majority of social networking site sharing features are combined together. Now that the friends are packaged, I'm going to use this component.

My notes were recorded during the development process and posted to the blog to sort out what I wrote down in Evernote. Blogs are not necessarily written according to the sequence of development dates for each part of the demo project.

Officials have detailed documentation on how to add components, and I am documenting some of the problems that I have encountered in the process of adding components.

1. Add an official code file:

Because to cross the platform, C + + 2 Java, C + + 2 object-c is necessary, but directly to the Java call method, Object-c call method into the project, do not adjust the words must be problematic. So the authorities have this solution:

#if (Cc_target_platform = = cc_platform_android) #elif (Cc_target_platform = = Cc_platform_ios) #endif

Use precompiled macros to solve cross-platform compilation, which is the scenario that the engine uses for cross-platform support. So the question comes, friends league here is a bit of a problem, but also do not blame him, the code said:

People are machine generated code, there are inevitably problems. What's the problem?

This is mostly Android, which is a problem inside theAndroid folder . He did not use #if (Cc_target_platform = = cc_platform_android) this to judge!!! So whether with VS, or with Xcode, will error, because cannot find <jni.h> files, resulting in compilation is not! (In fact, I have done a lot of work to add the Friend League component, but also encountered this problem, but limited to the ability at the time did not find the original problem caused by this cause).

So the solution is to use: #if (cc_target_platform = = cc_platform_android) This, the folder within the Class code processing, VS does not compile. This class is actually some Java calls C + +, C + + calls Java method, so directly on the Win32 can not be compiled.

2, sharing processing and Related:

When doing a custom button share, in the callback function of the button:

This will allow you to open the Friend League's share panel. It is important to note that the shared callback function needs to be a global function! that is, the sharetest in the code is a global function, which I think will be more understandable when I look at the actual code.

3, about the friend union's sharing function:

A big pit: use/data/data/com ... /files/the picture in the directory, UM's Java method can not respond, because its code does not judge this!! Always think the picture is empty .... Pit me for an afternoon.

Specifically: (AU component 2.0,cocos2dx v3.2)

Locate the file in the Friends League SDK package: Platforms\android\controller\com\umeng\social\ccumsocialcontroller.java this file. One of the methods provided is: Parseshareimage (String imgname), which is a function of creating Umimage objects based on the image's path. The implementation is based on imgname this parameter (parameter with what start, such as "assets/"), determine the picture storage path (such as Assets folder, network picture, res resource picture, is not the case is SD card directory), only these several judgments. But the problem comes, the game after the default image storage path is in the Data/data/com.xxx.xxx/files directory, so the friends of the league to provide the function can not find this path!!! I am not familiar with Android, so I spent an afternoon is not the reason why, and then do not use Eclipse debugging Debug Breakpoint, can only be printed by the log to find, it took a long time to find the problem. However, I learned something: Be good at finding a problem by log!

The solution is to modify this function to add a judgment:

1 Else if(Imgname.startswith ("/data")){ 2 3     if(!Textutils.isempty (imgname)) { 4 5File Imgfile =NewFile (imgname);6 7Shareimage =Newumimage (mactivity, imgfile);8 9     }Ten}

4. Share:

If you need to share, then the game's Android package must be a signature package (how to sign a lot of documents online), or you can not start sharing activity. The question seems to be (or I didn't notice) that the Allies did not mention it, so when I added the share, I couldn't open the shared UI, and it was a long time.

Cocos2dx-demo Demo Project: Part1

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.