Creating multi-platform games with Cocos2d-x

In this tutorial how to create a simple game using the Cocos2d-x framework in a Windows development environment and how to compile it to run on Windows 8 and Android.

What is Cocos2d-x?

Cocos2d-x is a cross-platform framework for games (and other graphical apps, like interactive books) based on the cocos2d for iOS*, but using C++, JavaScript*, or Lua* instead of Objective-C*.

One of the advantages of this framework is to create games that can be deployed on different platforms (Android*, iOS, Win32*, Windows* Phone, Windows* 8, Mac*, Linux*, etc.) keeping the same code base and making a few platform-specific adaptations for each one.

The source code of the framework is granted under the MIT License, and it be can be found here.

If you want to know more about Cocos2d-x and its documentation, check out:

Creating your first game

1. Download the latest version of the framework from the site and unzip it in your development environment. In this tutorial, the version 2.2.2 was used, and the framework was unzipped to the Desktop (C:\Users\felipe.pedroso\Desktop\cocos2d-x-2.2).

2. To create a new project on cocos2d-x, we are going to use a Python* script ( that creates the whole project structure inside the folder where the framework was unzipped. If you don’t have the Python runtime installed, download the 2.7.6 version from this link:

3. Open the command prompt (cmd.exe) and execute the following commands:

  • Go to the script folder (it’s important to run the script inside the ‘project-creator’ folder)
    cd C:\Users\felipe.pedroso\Desktop\cocos2d-x-2.2\tools\project-creator
  • Run the script with the following command:
    python -project MyFirstGame -package com.example.myfirstgame -language cpp

The parameters are as follows:
    project: The name of your project/game
    package: The package name of your app (e.g., com.myCompany.MyFirstGame)
    language: The programming language of the project (cpp, lua and JavaScript)

Note: To run the python command from the command prompt, add the folder where Python was installed to the environment variable path.

The created project will contain the base code of the game (Classes), the resources (images, audio, etc.), and one project for each framework-supported platform.

Building as a Win32 App (Windows* 7 or Windows 8 desktop mode)


1. Open the MyFirstGame.sln file inside the proj.win32 folder from the project directory using Visual Studio.

2. Build the project by pressing F6 (or use the menu Build -> Build Solution) and run the project pressing F5 (or use the menu Debug->Start Debugging).

If nothing went wrong, you’ll see the following window:

Building as a Windows Store App


To build your project as a Windows Store App, open the MyFirstgame.sln file inside the proj.winrt folder and build it using the same procedure that was used on the Win32 project.

After building and running, you’ll see the following screen:

Note: the cocos2d-x used in this tutorial didn’t work with Windows* 8.1.

Building as a Android App


In the same way that Python was added to the Windows path, add the directories, tools, and platform-tools from the Android SDK, the root directory from NDK, and the bin directory from Apache Ant in order to use them to build your app.

1. Open a new command prompt (cmd.exe) and run the following commands to configure the environment variables that are necessary to compile the Android app:

    set COCOS2DX_ROOT=C:\Users\felipe.pedroso\Desktop\cocos2d-x-2.2
    set NDK_MODULE_PATH=%COCOS2DX_ROOT%;%COCOS2DX_ROOT%\cocos2dx\platform\third_party\android\prebuilt

The variables we used are:

    COCOS2DX_ROOT: the directory where the framework was unzipped    NDK_TOOLCHAIN_VERSION: the version of the NDK toolchain that will be used to build the project
    NDK_MODULE_PATH: the modules that need to be included on the NDK build. In this case, we are using the prebuilt modules from cocos2d-x

2. With the environment variables configured, go to the Android project folder:

    cd C:\Users\felipe.pedroso\Desktop\cocos2d-x-2.2\projects\MyFirstGame\

3. Copy the game resources (images, sounds, etc.) to the assets folder:

    rmdir /S /Q assets
    mkdir assets
    xcopy /E ..\Resources .\assets

4. Run the following command to build the native modules:

    ndk-build.cmd -C . APP_ABI="armeabi armeabi-v7a x86"

This command will generate the native libraries for three different architectures: ARM, ARM-NEON*, and x86. This will allow your game to run on these architectures taking the best from them.

5. After finishing the build process, build the Android app with the ant command:

    ant debug

Now, to install the app in a device or emulator use the command:

    adb install -r bin\MyFirstGame.apk

After that, you just need to run your app:

OK, now your game can run on at least three platforms: Android, Windows 7, and Windows 8! 

For more complete information about compiler optimizations, see our Optimization Notice.


suraj k.'s picture

Hi Felipe

I am just starting out with cocos2d-x my self

I am using win7

I am getting error while debugging (MyFirstGame) in visual studio 12

can you please help me in that ?


Dror H.'s picture

A great tutorial about developing a multiplayer game like Fun Run with cocos2d-x can be found here:

Felipe P. (Intel)'s picture

Hi Mujtaba, how are you doing?

We need to check if the env variables are properly set. Please open your command prompt,execute the commands below and paste the results here.

echo  %Path%




Thanks a lot.



Mujtaba Z.'s picture

After running command 

ndk-build.cmd -C . APP_ABI="armeabi armeabi-v7a x86"

i m getting this error

Android NDK: D:\Softwares\cocos2d-x-2.2.3\cocos2d-x-2.2.3/external/libwebsockets
/android/ Cannot find module with tag 'android-ndk-r9d/ndk-build.cmd'
 in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?

Android NDK: The following directories were searched:
Android NDK:
make.exe: Entering directory `D:/Softwares/cocos2d-x-2.2.3/cocos2d-x-2.2.3/proje
jni/ *** Android NDK: Aborting.    .  Stop.
make.exe: Leaving directory `D:/Softwares/cocos2d-x-2.2.3/cocos2d-x-2.2.3/projec

Add a Comment

Have a technical question? Visit our forums. Have site or software product issues? Contact support.