How to create a new game

http://cocos2d-x.org/wiki/How_to_create_a_multi-platform_project_in_one_command_line


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

  1. Download and unzip cocos2d-x
  2. 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

The create-multi-platform-projects.py script will generate in thecocos2d-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 supportedtargets from onehost.

  • By builder we mean: the toolchain needed to compile the game
  • By host we mean: the Operating System that runs the builder
  • 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
Build requirements:
  • 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)
Additional requirements:
  • 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

Once 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.ios_mac

# This will open the Xcode project for your game
$ open HelloCpp.xcodeproj

From 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
Build requirements:
  • 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
Additional requirements:
  • Setup the correct environment variables

Needed environment variables

  • COCOS2DX_ROOT : should point to the root directory of cocos2d-x
  • ANDROID_SDK_ROOT : Should point to the root directory of the Android SDK
  • NDK_ROOT : Should point the to root directory of the Android NDK
  • NDK_TOOLCHAIN_VERSION : Which Android NDK toolchain should be used

And it is also recommended that you add the SDK 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-18

Now 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.apk

The game running on the Android emulator:

Addition Ubuntu requirements:

Windows Builder Requirements

Runtime requirements:
  • Windows 7 or newer
Build requirements: Additional requirements:

Once you have everything installed, you can run and compile your already generated project by doing:

# 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.sln

Visual Studio:

Game running on Windows 7:

Linux Builder Requirements

Runtime requirements:
  • Ubuntu 13.04 or newer
Build requirements:
  • 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.
Additional requirements:
  • Just run the install-deps-linux.sh script that is in cocos2d-x directory.

Example:

$ cd cocos2d-x
$ ./install-deps-linux.sh

Once 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/MyGameCpp

Game running on Linux:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值