Cocos2d-x Study Notes 06: How to port win32 to android

Source: Internet
Author: User

Cocos2d-x Study Notes 06: How to port win32 to android


This article mainly discusses how to transplant a win32 project to android, many articles on the Internet said different, because the android project configuration method of cocos2d-x seems to have been modified several times as if? I have never used the old version). This article provides a simple method.
Step 1: configure the android project Builder#1 open the cocos2d-x under the create-android-project.bat directory with an editor like ue
#2 edit these three variables

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQa004-0.png "/>

I will not explain it.

Step 1: Create an android Project
#1 run the cocos2d-x under the create-android-project.bat directory
#2 enter the package name and project name first. Be careful! This will delete and override the folder with the same name under your cocos2d-x installation directory, If you create a project with the same name, it is generally win32. 650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/Image(1).png "/> 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ92036-1.png "/> #3 then input support system version, android is backward compatible. I will write 5 here, that is, android2.1-update1650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/image(22.16.png "/> 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ91b2-2.png "/> then the project is created and you will find that under the cocos2d-x installation directory, multiple Test folders are added. Step 2: Import code and resources
#1 open Test650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ942b-3.png "/>
650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/image(32.16.png "/> #2 we can see three folders, android is the android project folder. Copy the Classes in your win32 project to the current Classes. Delete the excess cpp and h in the Classes, which are automatically generated by the project) copy Resources in your win32 project to the current Resources. Delete the unnecessary Resources in the Classes, which are automatically generated by the project)
Step 3: Edit mk
#1. Be careful! There are a lot of mk in the android project, and the mk positions are different in different tutorials! An error occurred while editing. It is invalid and related to the actual mk used ). In this example, we use mk650 under Classes) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ91316-4.png "/>
650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/image(42.16.png "/> #2 Add the following LOCAL_SRC_FILES: add the cpp file local_c_effecdes under your Classes: add the H file of the library you are using here. If yes, LOCAL_LDLIBS: add the lib file of the library you are using here, if yes
Here I am using the code in the previous example of "20 seconds for a man ".
Note that third-party libraries and additional libraries must be added by yourself. The default generated mk is not that full.
Step 4: run the build_native.sh script to edit the so library.
#1 run cygwin. bat in the installation directory of your Cygwin
#2 enter the current Test \ android path 650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/Image(5).png "/> note that the command syntax in cygwin is different from that in win.
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQa315-5.png "/> #3 run the build_native.sh script
650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQa929-6.png "/> the first compilation takes longer, of course, you can also copy the so in your own android project and other projects to save trouble. You can compile it, and then you will see that a lot of things are generated under the android folder.
Step 5: import to eclipse
#1. Be careful! Use Create project from existing source under the new android project. If you are using "import", it may not be recognized. 650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ94Z0-7.png "/> #2 the import is successful, and then the compilation is executed. Cocos2d-x authors recommend using sh to compile so, and then using eclipse to compile apk. 650) this. width = 650; "style =" cursor: default; "alt =" "src =" file: // C: /Users/goldlion/AppData/Local/Temp/enhtmlclip/Image(8).png "/>

650) this. width = 650; "border =" 0 "alt =" "src =" http://www.bkjia.com/uploads/allimg/131228/1FQ91C0-8.png "/>

Other considerations:#1. the win32 project is case-insensitive to resource files and android-sensitive. If an error occurs, give the person who provides the resource to you. #2. you can directly copy the project files in the win32 project, as well as the win32 folder, the project can be shared with VS, of course, the cocos2d-x is also so dry #3. vs uses the gb code, while android uses UTF-8. The solution uses iconv in vs. In addition, it is best to convert all data to UTF-8. There are many coding bulk conversion tools on the Internet #4. the horizontal and vertical screen of android is messy. In android, choose pDirector-> setDeviceOrientation (kCCDeviceOrientationLandscapeLeft). Use the Conditional compilation macro to turn it off.

 

 

 

In addition, on the problem of adding a third-party library in the android cocos2d-x, 6 groups of netizens wrote a document, very reference value. I have uploaded it to the attachment.

 

This article is from the "Old G hut" blog, please be sure to keep this source http://4137613.blog.51cto.com/4127613/758783

Related Article

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.