1. Download cocos2d-x
Http://cocos2d-x.org/projects/cocos2d-x/wiki/Download
cocos2d-x-2.1.4.zip @ June.18, 2013
We can see the latest version 2.1.4. This version provides a python command to build projects on various platforms, which is very convenient.
Download and decompress the package (it is recommended to decompress it to the main directory)
Ii. Download python
Http://www.python.org/getit/
Download 2.7.5 is recommended.
Python 2.7.5 Mac OS X 64-bit/32-bit x86-64/i386 InstallerPython 2.7.5 Mac OS X 32-bit i386/PPC Installer
Download, install, and enter python directly on the terminal. If version information is displayed, the installation is successful.
3. Establish cocos2d-x Project
Enter the terminal and execute the following command
cd ~/cocos2d-x-2.1.4/tools/project-creator/python create_project.py -project game01 -package com.ookcode.game -language cpp
Create_project.py requires three parameters (Project name: game01, package name: com. ookcode. game, language: cpp | js | lua)
If the execution is successful, the following information is displayed:
proj.ios : Done!proj.android : Done!proj.win32 : Done!proj.mac : Done!proj.blackberry : Done!proj.linux : Done!proj.marmalade : Done!New project has been created in this path: /Users/ookcode/cocos2d-x-2.1.4/projects/game01Have Fun!
Go to the game01 directory and you can see these projects
Classes Resources proj.android proj.ios proj.mac proj.win32proj.blackberry proj.linux proj.marmalade
How about it? All platforms have been set up for you and share a Classes folder. That is to say, you have updated the code on a platform and all platforms have been updated.
4. Edit the ios Project
Go to the game01/proj. ios/directory and double-click game01.xcodeproj (do not say you have not installed xcode)
Then click run to start running.
I made a very 2 mistake here, that is, I have been running in the cocos2dx directory, and I cannot run it.
Game01 should be selected here, otherwise it will become a constant build cocos2dx.
This HelloWorldScene. cpp is your code. You can modify it on your own, but since it is used by all platforms, you can remember to run it on other platforms.
5. Edit the android Project (important: This is complicated)
1. Download ADT Bundle
Http://developer.android.com/sdk/index.html
(Decompress the package to the main directory and rename it as adt-bundle. It is convenient to write the path below)
2. Download NDK (the latest version is: android-ndk-re8)
Http://developer.android.com/tools/sdk/ndk/index.html
(Extract to the main directory)
3. Install the CDT plug-in for Eclipse
Open eclipse and choose Help/Install New Software.
In the Work With drop-down box, select your own eclipse version name, and then select Programming versions in the plug-in to open the drop-down list.
Install C/C ++ Development Tools and restart eclipse
You can create a new c ++ HelloWorld project.
The following error may occur during running:
Gcc: command not found
G ++: command not found
Choose xcode> preferences> Downloads.
You need to download and install Command Line Tools. After the installation is complete, restart Eclipse and run the c ++ project again. You will see the long-overdue HelloWorld in the Console!
4. configure global variables
Enter the terminal and execute the following command
vim ~/.bash_profile
Edit by I and enter the following path
export COCOS2DX_ROOT=/Users/ookcode/cocos2d-x-2.14/export NDK_ROOT=/Users/ookcode/android-ndk-r8eexport ANDROID_NDK_ROOT=/Users/ookcode/android-ndk-r8eexport ANDROID_SDK_ROOT=/Users/ookcode/adt-bundle/sdkexport PATH=$ANDROID_NDK_ROOT:$PATHexport PATH=$ANDROID_SDK_ROOT:$PATH
Press ESC and enter wq to save and exit (the Basic vi command will be executed)
* ***** Here is my path. Remember to replace it with your own *******
5. Use NDK to compile android Projects
Enter the terminal and execute the following command
cd ~/cocos2d-x-2.1.4/projects/game01/proj.android./build_native.sh
Then there is a long compilation process.
Compile++ thumb : cocos2dcpp_shared <= main.cppCompile++ thumb : cocos2dcpp_shared <= AppDelegate.cppCompile++ thumb : cocos2dcpp_shared <= HelloWorldScene.cppCompile++ thumb : cocos_extension_static <= AssetsManager.cppCompile++ thumb : cocos_extension_static <= CCBFileLoader.cpp
………
………
When you see
Install : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.somake: Leaving directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'
The compilation is successful.
6. Import the android Project
Right-click eclipse, and choose new> project.
Select Android Project from Existing Code
Browse to the proj. android directory of game01
This error was found after the import.
This is because the cocos2dx file is not properly included.
Right-click the project and choose properties> Java Build Path.
Click Link Source in Source
Browse up to/cocos2d-x-2.1.4/cocos2dx/platform/android/java/src
Take a name and click "OK". The error is eliminated!
Bytes --------------------------------------------------------------------------------------------------
Updated on April 9, July 31, 2013:
You can directly/cocos2d-x-2.1.4/cocos2dx/platform/android/java as an android project import, and then do not need to set Link Source, once and for all!
Bytes --------------------------------------------------------------------------------------------------
7. Create an AVD Simulator
Note: cocos2d-x above 4.0.3 simulator to run, the real machine does not matter
When creating an AVD, remember to check the Use Host GPU check box.
Right-click the project and choose Run As> Run deployments> Target.
Enter at the bottom
8. Run the project
Right-click the project and choose Run As> Android Application.
Then select the created AVD, and then you can have a cup of tea first ~
9. Edit the project
Do not write c ++ code in eclipse. CDT cannot handle it.
As mentioned above, all platform projects share one classes. Therefore, we can use xcode to open the ios project.
Open the HelloWorldScene. cpp file and make some simple modifications.
Find this line of code and modify a font for it.
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);
Change
CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "fonts/Marker Felt.ttf", 128);
You may wonder why fonts/Marker Felt. ttf is written like this"
For ios support, write Marker Felt directly, but Android cannot. We can see that there is a fonts directory under the directory of the android project, so we have to use this method to get Android support.
(However, I am confused that ios clearly does not use the fonts directory. How does it determine the font)
10. Run the modified project
Click Run IN xcode
Did you find that the font has changed!
Then there is the android project. Because the code has been modified, it must be re-compiled.
Enter the terminal again and enter the following code
cd ~/cocos2d-x-2.1.4/projects/game01/proj.android./build_native.sh
This time it will not take that long to compile the code of cocos2dx.
Using prebuilt externalsmake: Entering directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'Compile++ thumb : cocos2dcpp_shared <= HelloWorldScene.cppSharedLibrary : libcocos2dcpp.soInstall : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.somake: Leaving directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'
The code above indicates that the compilation is successful.
Go back to eclipse, right-click the project, and choose Run As> Android Application.
Vi. Conclusion
Cocos2d-x environment is really very annoying, it took a whole day to build a good, but also encountered a variety of errors, so specially registered a blog, to record this difficult environment
Provide some help to friends who are struggling.
I have been writing for two hours. This is my first time to write something. I am not very clear about it. Please forgive me. If you have any questions, please let me know.
I'm also learning cocos2d-x now, I don't know if any friends can communicate with me -. -(I am 93 years old, 2 diaosi, technology house, unmarried, wood has sister paper 0.0)