In this post, we’ll get things up and running cocos2d-x in our machine. This will include information on downloading the framework and creating a project as well as an overview of the basic structure of a Cocos2d-x application.
I will also point you to some extra tools you should consider getting to help you with the development process.
Downloading Cocos2d-x Manual
I recommend that you save all the files we are going to download now to the same folder
- Go to cocos2d-x download site and download lastest version of cocos2d-x, for this tutorial, I will be using version Cocos2d-x 3.17-2.
- When download complete, uncompress the files somewhere in your machine so you can remember later.
- Open folder you just uncompress and view the README.md file, find Build Requirements header and you can see python, NDK, android studio, Xcode and JDK version is required to build games.
- Then go to python site to download python.
- If your machine run Mac OS you need install XCode.
- If you haven’t JDK in your machine, go to oracle site and install JDK.
- Next go to android developer site to install Android Studio.
- Lastly, go to ndk site and download the latest version of the NDK for your target system.
- You can do this by typing cd (that is, cd and a space) and then dragging the folder to the Terminal window and hitting Enter. In my machine this looks like:
- Next typy
- Hit Enter. You will be prompted for the paths to the NDK, SDK and Apache ANT root. You must drag each one of the folders to the Terminal window, making sure to delete any extra spaces at the end of the path and hit Enter.
- If your use Mac, the last step is to add these paths to your system. Follow the last instruction in the window where it says: Please execute command: “source /Users/YOUR_USER_ NAME/.bash_profile” to make added system variables take effect. You can copy the command inside the quotes, paste it, and hit Enter.
Hello Cocos2d-x World
Now, it’s time for test your installing, say hello to cocos2d-x
You can create a new Cocos2d-x Project by run cocos script
$ cd cocos2d-x
$ source FILE_TO_SAVE_SYSTEM_VARIABLE
$ cocos new MyGame -p com.your_company.mygame -l js -d NEW_PROJECTS_DIR
$ cd NEW_PROJECTS_DIR/MyGame
Then hit Enter. If you choose not to give a directory parameter (-d), the Cocos console will save the project inside your current folder. You also can create a C++ project or Lua project with `
-l cpp` or `
-l lua`. You can replace
NEW_PROJECTS_DIR with other folder name that you prefer.
Run Your Game
Now you can go to your desktop, or wherever you chose to save your project, and navigate to the MyGame folder. Now you can run your game depend of your target runtime system, you run script respectively.
Build and run a new project for iOS
$ cocos run -p ios
Build and run a new project for OSX
$ cocos run -p mac
Build and run new project for win32
$ cocos run -p win32
Build and run new project for web
$ cocos run -p web
And you’re done.
If you see any issue or error from beyond process, Share your thoughts in the comments below :D, thank you.
Life teaches us through our mistakes.Haemin Sunim