Need help getting started with Cocos2d-x to build for iOS & android

Need help getting started with Cocos2d-x to build for iOS & android
0.0 0


Android Studio support is new for us and my understanding is that each Android Studio release is changing drastically but also adding functionality for debugging c++, etc. I don’t know about mixing Java and C++ really, but maybe @IQD @pococogames can also help with this.


If you want to have a hard time, go for it. If you can use C++/REST implementations for your feature it will make your life so much easier.

If you really have to mix Java with C++, I suggest using/reading into djinni. A tool for generating cross-language type declarations and interface bindings made by the dropbox developers.


Sorry, but i don’t understand you. Every people sucks with computers. Me too. Do you think it’s possible to solve everything in a fucking easy way? Or everything works correctly? NO! If you can’t figure it out, or can’t find any solution try again until it works. If you don’t like it, choose another hobby.


I don’t know if I should mix or not. I just asking for what I need to do next while developing game specifically for android.


The thing is: we don’t teach people how to develop games. We provide a game engine for you to exploit how you see fit. There isn’t a right or wrong way (within reason).

There are many books about the concepts for developing games. I can recommend a number of them if you really want some specific titles. Packt Publishing also has titles, some of which are written by developers on these very forums.

When I started a few years ago, I struggled like you did. I didn’t have anyone to teach me either. I had to dive in and get my feet wet (and then once they were wet I decided instead to bang my head against the wall :slight_smile: ). Start small. Create a sprite, put it on the screen, move it around, add touch events, etc.

cpp-tests has plenty of code. Use it. Every aspect of the engine is covered here.


I’m not asking about that. You understand me wrong. I just need a simple examples of next simple steps. I know how to develop games, but using cocos2d-spritebuilder.


Sorry, what steps exactly then? If they are Cocos2d-x specific steps we can help. If they are general tools related (Android Studio) or concept related we might not be the best resource. Google will have better docs about their products than we will.


You generate the project files for Eclipse and Android Studio with the cocos console tool. The cocos console tool has an integrated help system, which you can get to by calling cocos -h.

There is no need to use any of the IDEs. That’s completely your choice. cocos console is just using the build-system from the specific IDE. E.g. gradle when using AS.

Developing for Android is not any different to developing for iOS or Desktop. You are just implementing your game in C++, which is then compiled to the specific platform with cocos compile.


I’m using Cocos2d-x for about 4 years and I was never be able to develop for android.

I tried using Eclipse + Adt bundle years ago, using version 2 of Cocos2d-x and I got running on a simulator.

After a few years, I wanted to do that way but I can’t find the same sources, then I tried with Android Studio without luck.

I’m finishing my iOS game and I would love to port it to Android.

I have seen in the forum that we can use Visual Studio to work for Android, but my problem is I’m using cocos2d-x 3.6 and I have a lot of animations made in CocoStudio.

How do you do @slackmoehrle to develop for Android? I have both Windows and MacOS and an Android device.


Why you want to use java codes in the C++ project? You already use NDK to build c++ project to android platform. I developed an android game with cocos2d-x and I never use java until today.

If you want to use network/social plugins, you need to use SDKBOX. Help documents is here;

if you still want to use java in the c++ project, your answer isn’t here. You may search “How to use java in c++ project, ndk, android…etc” terms in google.


Just my 2c regarding the answers from @pococogames

As I understand, he wants to use some platform specific features.

Well, I already answered that question.

This is an option, not a requirement.

Use a cross-platform language like Swift or Haxe instead.


yep, haxe is good idea. But I don’t know, is there any cocos2d port for haxe?


As I know, there is no Haxe port and I can imagine there never will be. It would be a lot of work to support all backends.
cocos2d-x is just a cpp framework, so it would target only the Haxe cpp backend anyway.

If you don’t want to use cocos2d-x tho, there exist plenty of awesome Haxe game frameworks.


Yep I had heard Haxeflixel. Did you use haxe? I just wonder, what do you think about cross compiler side of haxe? is it perfect?


I benchmarked and tested the major frameworks including HaxeFlixel. HaxeFlixel has not the best performance, but plenty of cool features.

Yes, I’m using Haxe with Kha and various other Haxe libs.

It’s just awesome. The language features are really great and the performance, depending on the framework, is outstanding. Despite using a GC, it’s nearly on par with C/C++ code. There never will be the perfect solution, but using a Haxe framework comes really close to that.
One codebase reaches Windows, Mac, Linux, iOS, Android, Windows Phone, HTML5, Flash, Raspberry Pi, Xbox One, Tizen, PS Vita, PS4 and even Unity 3D (there are even more backends in the working).
The supported backends are also depending on the framework used.

Look at some benchmarks:

cocos2d-x is below LibGDX (around MonoGame), as it heavily relies on a scene graph, which is hammering on the performance. The other frameworks do no rely on a scene graph.

E.g. my bunnymark on a Samsung Galaxy A5 (2016):
cocos2d-x: 2000 bunnies @ 60fps
Kha: 9000 bunnies @ 60fps

Real world results are depending on various other parameters and every engine/framework supports different features and have different usages and implementations.


Hey thanks to detailed reply. Haxeflixel developers really love their development environment. I will try it in the future.

Did you try in ios platform? I heard cocos2d-x performance isn’t better in android than ios. I had heard kha performance. I carried out a benchmark between unity and cocos2d-x with iphone4s.

if you have iphone4s device, may you try benchmark with kha and share results to me?

#57 created when I create project with source code, and without when using libs. Thats a bug?

So, lets pick an example - I created project with pre-compiled libs and now I want to add simple 1 in-app for android. How can I do that?

As I said before in previous my post, I don’t know it this needed, just asking.[quote=“pococogames, post:50, topic:33909”]
You already use NDK to build c++ project to android platform. I developed an android game with cocos2d-x and I never use java until today.

Thats interesting. And I don’t want to use sdkbox or any other, I just want to implement my open source code.

Yes, I would need to load and show game center score to user in android. Or this possible using only C++ code?


You’r welcome.

Yeah, it’s cool.
The problem with HaxeFlixel is it’s performance. It does not come close to other solutions.
Another thing you have to consider is it’s Flash API. Maybe you don’t like that.

Not at the moment. But look at the benchmark from @nivrig. I added the link in my previous post. He was running the bunnymark on iPhone 6s.

Yeah, but the difference is minimal. The performance gaps between cocos2d-x and other frameworks is really the same on every platform, be it iOS, Android or Desktop. It’s mainly because of the scene graph and differences in the backends. E.g. Kha and other frameworks even support Metal and Vulkan.

Plans are to beat Orx :wink:

Unfortunately I only have a non jail broken iPhone 4 at the moment. I will ask around if some one did a benchmark on various devices.


Could be a bug. Normally you have to use the --android-studio option to generate an AS project. Without that option, it will generate an Eclipse project.

With the IAP solution of your choice. SDKBox, MaaS solutions, IAP frameworks in C++ or with REST API.

It’s only needed, if your framework you want to use is Java only.

SDKBox is a framework for various “plugins” like IAP. They basically wrap some other Open Source frameworks.

No. Game Center is an Apple exclusive framework. You have to use an alternative.
IIRC you are not even allowed to use their REST API on other platforms.


Sorry, I just call it currently like that I don’t know how it’s in android, but I know there is something same, where I can store leaderboards and scores. So I just want to implement it in my game.[quote=“iQD, post:59, topic:33909”]
Normally you have to use the --android-studio option to generate an AS project. Without that option, it will generate an Eclipse project.

Can you please give an example? Because I don’t see how I can do this: