Cocos2D Build
How to create a new game
This guide will show you how to create a new project, how to compile and and run it in the different platforms.Quick guide
Note: These instructions are only valid for cocos2d-x v3.0-alpha0 or newer- Download and unzip cocos2d-x
- Run the script
$ cd cocos2d-x $ ./create_project.py -project MyGame -package com.MyCompany.AwesomeGame -language cpp

Options:
-l cpp
for a cocos2d-x C++ project-l lua
for a cocos2d-x + Lua bindings project-l javascript
for a cocos2d-x + JavaScript bindings project
Detailed information
Thecreate-multi-platform-projects.py
script will generate in the cocos2d-x/projects
directory the needed files to compile your game for iOS, Android, Linux, Mac and Windows.The source code files are shared across all the different builders. And there is one builder for each platform, except for iOS and Mac where the builder is shared.
Each builder has its own requirements, and it is not always possible to generate builds for all the supported
targets
from one host
.- By
builder
we mean: the toolchain needed to compile the game - By
host
we mean: the Operating System that runs thebuilder
- By
target
we mean: the binary (our game) for a particular supported platform
iOS and Mac Requirements
Runtime requirements:- iOS 5 or newer
- OS X 10.7 or newer
- OS X 10.7.5 or later (10.8 are 10.9 supported as well)
- Xcode 4.6.3 or later (5.0 is supported is supported as well)
- A valid iOS developer account is needed in order to test your games in the device and to publish it on the iOS App Store. Without the developer account you can only test them on the iOS Simulator
- A valid Mac developer account is needed to publish your game in the Mac App Store
# This is were your project game was generated $ cd cocos2d-x/projects/MyGame/proj.ios_mac # This will open the Xcode project for your game $ open HelloCpp.xcodeprojFrom that single Xcode project you can generate
target
builds for iOS and OS X.Xcode project:

Game running on Mac:

Game running on iOS Simulator:

Android Requirements
Runtime requirements:- Android 2.3 or newer
- OS X 10.7 or newer
- or Windows 7 or newer
- or Ubuntu 13.04 or newer [*] (see below for further info)
- and:
- Android SDK
- Android NDK
- Setup the correct environment variables
COCOS2DX_ROOT
: should point to the root directory of cocos2d-xANDROID_SDK_ROOT
: Should point to the root directory of the Android SDKNDK_ROOT
: Should point the to root directory of the Android NDKNDK_TOOLCHAIN_VERSION
: Which Android NDK toolchain should be used
tools
and platform-tools
in the path.Example: edit your
~/.profile
(for OS X), or ~/.bashrc
(for Ubuntu) and add the following lines:export NDK_TOOLCHAIN_VERSION=4.8 export NDK_ROOT=~/bin/android-ndk-r9/ export ANDROID_SDK_ROOT=~/bin/adt-bundle-mac-x86_64-20130917/sdk export COCOS2DX_ROOT=~/progs/cocos2d-x export PATH="${PATH}:$ANDROID_SDK_ROOT/tools:$ANDROID_SDK_ROOT/platform-tools"Update the Android project
Once you have all the variables set, go to the already created project and update the project files by doing:
$ cd cocos2d-x/project/MyGame/proj.android/ # # Determine which targets are installed # As you can see, there is only one target and its name is "android-18" # $ android list targets Available Android targets: ---------- id: 1 or "android-18" Name: Android 4.3 Type: Platform API level: 18 Revision: 2 Skins: HVGA, QVGA, WQVGA400, WQVGA432, WSVGA, WVGA800 (default), WVGA854, WXGA720, WXGA800, WXGA800-7in ABIs : armeabi-v7a # # Update the project with the correct target # ( The following 2 steps should only be done once) # $ android update project -p ./ --target android-18 $ android update project -p ../../../cocos2dx/platform/android/java --target android-18Now compile your project
# Builds the c++ code $ ./build_native.sh # Builds some Java files and generates the executable $ ant debug $ cd bin # Installs the executable on a device (if attached), otherwise on an emulator (if it is running) $ adb install MyGame-debug.apkThe game running on the Android emulator:

Addition Ubuntu requirements:
- You need to install Oracle Java
- If you are in Ubuntu 64-bit, you need to install these ia32 libraries
Windows Builder Requirements
Runtime requirements:- Windows 7 or newer
- Windows 7 or newer
- Visual Studio 2012 Express or newer (the Ultimate and Professional versions are supported as well)
- You need to download and install Python 2.7
# This is were your project game was generated C:\> cd cocos2d-x\projects\MyGame\proj.win32 # This will open the Visual Studio solution C:\cocos2d-x\projects\MyGame> start HelloCpp.slnVisual Studio:

Game running on Windows 7:

Linux Builder Requirements
Runtime requirements:- Ubuntu 13.04 or newer
- Ubuntu 13.04 or newer
- gcc 4.7 / clang 3.3 or newer. The will be installed automatically the by
install-deps-linux.sh
script.
- Just run the
install-deps-linux.sh
script that is in cocos2d-x directory.
$ cd cocos2d-x $ ./install-deps-linux.shOnce you have everything installed, you can run and compile your already generated project by doing:
# This is were your project game was generated $ cd cocos2d-x/projects/MyGame/proj.linux # This will compile your game $ ./build.sh # This will run your game $ ./bin/debug/MyGameCppGame running on Linux:

Google + Facebook Tweet Sina