2014-05-11

Cocos2d-x 3.0 Setup (Include Git & Github support)

Recently, I am going to try the latest cocos2d-x 3.0 final version. Here is the note to use cocos2d-x 3.0 with the source control of Git & Github;





Steps to setup



1. Download and zip cocos2d-x 


Simply following the instruction at cocos2d-x official site ( http://www.cocos2d-x.org/download) to download.


2. Setup the directory structure 


The following is my structure related to the cocos2dx
  • /w/cocos2dx/engine - Place the cocos2d core at here. (The pack of the cocos2d-x project will be placed here)
  • /w/cocos2dx/project - The project directory, where is my code placed at.
  • /w/cocos2dx/script/ -  The script files simplify some task. (will discuss later)


3. Run the setup 


Just run the following commands

cd /w/cocos2dx/engine/./setup.py

It will change your .bash_profile to add some environment variable

Prepare the following information:  

  • ANDROID_SDK_ROOT
  • ANT_ROOT

4. Create a new project using script


Use the following command to make a new project :
cd /w/cocos2dx/engine/tools/bin/cocos_console/./cocos.py new -p ken.game -l cpp Example1 -d /w/cocos2dx/project/


5. (optional) Trim down the project size

Since every project made by the cocos.py will make a copy of the cocos2d engine inside the project. If you want to share the engine code among different projects, we can do steps below; However, if you are going to hack the engine code and don't affect other project, you shouldn't do that. One more point, this action will place the cocos2d engine source code outside the source control scope. (Pro: save space;  Con: change won't be logged)

Just do the following to keep the project smaller
mv ./cocos2d ../ln -s ../cocos2d ./cocos2d


6. Setup GIT 



Do the following step to setup GIT. 
  • Install Git. (suppose Xcode will help to install the git, but it doesn't happened. just go to http://git-scm.com/ to download it) 
  • Add the .gitignore to the project directorycd /w/cocos2dx/cp ./script/.gitignore project/Example1
  • Git initialisation
    run "git init" in your project directory
  • Add to SourceTree (SourceTree is a GUI version of Git. available at http://www.sourcetreeapp.com/)Select "Add Working copy" and the select the project directory (w/cocos2dx/project/Example1)
  • Commit the work at SourceTree


7. Sync with Github 


In the previous step, we just put the source code to the local repository; It will be more safe if we put the source on the remote location. Here, I select github. Besides github, there are many alternatives such as you setup your own git remote server or using bitbucket. 

There are the steps to setup repository in github.


     
  • Create a repository in www.github.com. (Assume that you are already registered) and copy-and-paste the git url.
  • Open SourceTree and select your project to add a remote location- Select the project.
    - Choose "Repository -> Repository Setting" in the menu.
    - Select the "Remotes" Tab.
    - Click the "Add" button; It will show the "Add Remote" Popup.
    -  Enter "origin" in "Remote Name" and the given github url in "Remote Path"
  • Pull the master branch to github (origin location)

8. Start coding and Enjoy it


Open the project in Xcode, build and Run it. 



Tools involved:


  • Cocos2d-x : the core engine to play with.
  • Python - the script interpreter to run cocos.py
  • Git - The tool used for source control 
  • SourceTree - the GUI of git, simplify the way to handle git 
  • Github - The free repository available in the internet so that can keep a copy in the cloud









No comments:

Post a Comment