How to export your game with Cocos2d-x

Cocos2d-x is a game engine that can used by GDevelop to render HTML5 games. By default, the underlying rendering engine used by GDevelop when previewing or exporting HTML5 games is Pixi.js.

Cocos2d-x provides an engine that enables games to be both exported to the web (using HTML5 and webGL) and to native platforms, including iOS, Android, Windows, Mac OS X and Linux. In both cases, GDevelop game engine is the same, but the rendering is done with Cocos2d-x, using either WebGL on the web or native OpenGL on the other platforms.

Export with Cocos2d-x is still experimental. Also, native export to iOS, Android, Windows, Mac OS X and Linux involves installation of some additional tools.
If you want to read about the normal export, read How to distribute your game.

Export your game

To export with Cocos2d-x, make sure that your game is using the HTML5 platform. In the File menu, choose Export to the web.

Choose Export to a website or native game with Cocos2d-x (experimental), and select a folder where the game will be exported (be sure to choose an empty folder as the content will be erased!). Finally, click on Export.

Your game is now available in the folder you've chosen.

Publish your game on a website

Similar to the default export to a website, you can now upload all the files in the folder of the exported game to a website. Then, open the page with a browser to play to the game.

You can't play directly to the game by opening index.html. You need to upload it to a web server.

Advanced: export your game to native platforms

Export to a native platform involves the compilation of your game into a native executable that can be launched on the platform. First, you need Cocos2d-x tools to be installed:

  • Download Cocos2d-x 3.10 using this link.
  • Extract the content of the zip file somewhere on your computer.
  • Install Python on your computer. Python is a programming language used by Cocos2d-x command-line tools. On Mac OS X and Linux, it is installed by default. On Windows, you must download the Python installer and run it to install Python.
On Windows, when installing Python, make sure to check Add Python.exe to the system PATH:
  • Check that Python is working : open a command line/terminal, type python and press Enter. If python is launched, you're ready to continue.
To open a command line (also called Command Prompt) on Windows, type cmd in the start menu.
On OS X or Linux, open the Terminal app.
  • Open a new command line and go to the directory where Cocos2d-x was extracted. To do this, type cd followed by the path of the folder of Cocos2d-x. Put quote at the beginning and the end of the path if it contains spaces.
For example:
cd C:/Users/Florian/Downloads/Cocos2d-x-3.10 on Windows,
cd /Users/florian/Downloads/cocos2d-x-3.10 on OS X.

  • Install Cocos2d-x by typing python setup.py in the command line (or C:\Python27\Python.exe setup.py on Windows). When asked for path of some tools, just press Enter.
  • Check that Cocos2d-x is properly installed: reopen a new command line and type cocos in the command line. You should see some text explaining the available cocos commands.

Congratulations, Cocos2d-x is now installed on your computer! Now you need to create a game skeleton with Cocos and export your game with GDevelop to be able to compile it.

For all platforms: create the Cocos game skeleton and export from GDevelop

The first time you want to export your game to a native platform, you must use the cocos program we've installed in the previous section:

  • Open a command line.
  • Type cocos new -l js MyGame -p com.yourname.mygame and press Enter. Replace MyGame by the name of your game. com.yourname.mygame is a package name used to identify your game on the stores.

Wait a bit: Cocos will now create a new folder with the name of your game. It will contains everything needed to compile the game.

  • With the command line, go in the folder created by Cocos2d-x: cd MyGame (replace MyGame by the name of your game).

  • Now, using GDevelop, choose to export your game with Cocos2d-x (see the first section if you need help). Choose the folder created by Cocos2d-x as the export folder in GDevelop. Finally press Export.

You're ready! You now have a full game exported with GDevelop and ready to be compiled with cocos: see the sections below to know how to export for a specific platform.

Later, if you change your game and want to rebuild the native games, just export the game in the same folder using GDevelop, and relaunch the cocos commands explained in the sections below.

Android export

FIXME This section is a draft and not yet complete. You can help by completing it with more information!

  • Download and install the Android SDK.
  • Download and install the Android NDK.
  • Relaunch python setup.py (or C:\Python27\Python.exe setup.py), using the command line, in the folder of Cocos2d-x.
  • Create a keystore inside the game folder:

The following command requires keytool which is installed as part of the Java Development Kit (JDK). It will create a keystore in the current folder, just remember to change 'Yourpersonalfile_title' and then press enter. You will be asked a few questions and then be prompted to create the keystore, just type yes and press enter.

keytool -genkey -v -keystore Yourpersonalfiletitle.keystore -alias aliasname -keyalg RSA -keysize 2048 -validity 10000

  • In the game folder, open the file frameworks/runtime-src/proj.android/jni/Application.mk and add APPPLATFORM := android-9 at the end. * With the command line, in the folder of your game, launch cocos compile -p android -m release. * The first time you compile this project you will be asked to enter the path to the keystore at the end of the compilation. Enter the full path, including the filename i.e F:\GDevelop\cocos2d-x-3.10\MyAwesomeGame\mystore.keystore and press enter. You will then be asked for the alias_name and password you entered when creating the keystore. Wait for the compilation to be done: this can be quite long the first time you launch it. When it's done, an APK file should be available in the folder publish/android. ==== Mac OS X export ==== * You need to have XCode installed on your Mac. You can install it from the App Store. * With the command line, in the folder of your game, launch cocos compile -p mac -m release. Wait for the compilation to be done: this can be quite long the first time you launch it. When it's done, the app is available in publish/mac. ==== iOS export ==== * You need to have XCode installed on your Mac. You can install it from the App Store. * FIXME Open the XCode project * FIXME In XCode, click on Play. Wait for the compilation to be done: this can be quite long the first time you launch it. ==== Windows export ==== FIXME This section is a draft and not yet complete. You can help by completing it with more information! * Install Visual Studio Community 2015. This is the compiler of Microsoft and is required to compile your game to a Windows executable. Choose Advanced installation, and check Windows 8.1 and Windows Phone 8.0/8.1 Tools: * With the command line, in the folder of your game, launch cocos compile -p metro -m release <note>If the result of the command is Can't find correct Visual Studio's path in the registry.'', then you have not Visual Studio properly installed. Check that you've installed it, close and relaunch the command line after the installation.</note> Wait for the compilation to be done: this can be quite long the first time you launch it. * FIXME Export your game for the Store.