Moving from LibGDX to Cocos2d-x

Hi everyone!

I’ve just started working on cocos2d-x and moving my games from libGDX.
Generally API is pretty similar, most of the API’s exists in both frameworks.
But still i’ve problems adopting to C++, and generally the way cocos2d-x is used.

So i’m asking for some guides regarding general cocos2d-x games structure like Assets Loader, memory management, good practices with code structure etc.

I’m still confused will all static create methods and init, also with reference counters. For example for custom classes that will be used as some kind of model, do i have to extend cocos2d-x Ref class or no, what benefits do i get if i extend ? Also for example in libGDX it’s really easy to do some custom drawing directly on OpenGL, but i’m not sure how to do it in cocos2d-x, like drawing meshes and binding textures etc.

thanks in advance,
BR

Hi Milos :slight_smile:

Welcome to the world of cocos2dx! As someone who have gone trough same transition from libGDX to cocos2dx, I feel obliged to share some experience with you :wink:

We decided to leave LibGDX because it’s not on the same level as cocos concerning cross platform support, especially since there is more or less usable windows phone 8 support in cocos.

Some things you should be aware of:

  • Big players on the market are supporting cocos2dx so you should expect it to last for at least couple of years from now.
  • Documentation and wiki is messy and not as well cared.
  • Constant improvements in code base - strongly advise you to track this rep . WP8 is lagging behind a bit usually.
  • Bigger community, although you will notice it is 90% from China with post like “I NEED THIS, GIVE ME THAT, MY CODE IS NOT WORKING etc.”, so don’t expect plenty of constructive approach here at forum, unless you learn some Chinese. I assume docs and wiki are in better shape in Chinese versions. I got impression that libGDX guys are more oriented towards developers.
  • A lot of plugins and good support for third party monetizing platforms - many of them for Chinese market though.
  • Some really neat optimized code for batch operations.
  • IDE for Cocos2dx has been released recently, but I could not find it useful for cpp development ( only JS and Lua ).
  • Make sure you chose one IDE for development - VS or Xcode - you probably wont be able to debug cpp code from eclipse on android and emulator is not very cocos2dx friendly.

Concerning your questions:

  • Organise resuorces ( fonts, spritesheets and sounds ) in folders based on the resolution. Try to make assets for multiple resolutions and decide in the AppDelegate class which ones you need based on the screen resolution.
  • Use this to load textures asynchronously and the callback method to update the UI : TextureCache.getInstance().addImageAsync(tx_player,this,this.textureLoadedCallback)
  • Make sure you use 4444 textures for Android - iOS and WP8 do not support it properly
  • Read the code style guidelines ( they took it from google :slight_smile: )
  • Reference counts are managed automaticly - just don’t dare to use new operator for instancing objects, use static create() instead.
  • For model you can use Ref or Node ( a bit of overkill ) but good thing with nodes you can use cocos parent-child memory management and other cool methods of that class.
  • Prepare to work your ass of if you wanna do some custom drawing in cocos2dx, as said docs are awefully orginised and don’t relay 100% on those since it happened to me and my colleagues that we lost days because sb forgot to update docs and comments in code. Second problem is that you have to make sure it works on all platforms.

Good luck :wink:

1 Like

Thanks for tips! I do have some more questions :smile:
I’ve noticed that there is no camera in cocos2d-x, what do we use instead ?
Well, regarding resolutions, i’m kinda use to develop for one fixed resolution with one set of assets and show more of the world/ menus depending on screen size. Does cocos2d-x support something like that ?

Camera is added since v3.3.

About document, we are in progress, as you can see here https://github.com/chukong/programmers-guide.

In fact, all cocos2d-x mostly focus in English forum. Chinese forum is other guys maintain.

@milos1290 Yes, cocos2d-x supports the way you use resolutions. You have a design resolution size (the fixed size you develop for), and then according the resolution policy you use, you will have more space on the sides (well, that’s the mode I use).

@zhangxm Great work. I’ll try to contribute a “Android with Gradle Installation and Setup” chapter, since I got this working for my projects (it’s actually not that hard). A chapter “Debugging on Android” would be great too. Unfortunately, I didn’t get that working …

Is there any place you would prefer to discuss this guide?

@Fradow
Thanks.
I think you can create a new ticket here: http://discuss.cocos2d-x.org/category/cocos2d-x-dev-discussion.

Thanks for feedback,

I’m also curious, why can’t we resize game window on mac, it would be great to have, and you can easily test different aspect ratios with just resizing main frame ? Coming from libgdx that is a great feature that removes needs for different mobile devices with different aspect ratios, since you can easily test it on desktop.

BR

@zhangxm Thanks.

@milos1290 What device do you want to test on? On iOS, you can test everything on simulator, which is quite good. On Android, just generate emulators for the sizes you want to test (I advise you to use GenyMotion, not the stock emulator). I don’t have clue on other devices (including Mac, it would be a significant overhead for my projects to have compatibility).

@Fradow Yeah i know, this can be done much easier, if cocos2d-x supports window resize on desktop, you could easily test your game on multiple devices, because you can resize window while game is running, and change size of canvas, and you will basically get idea what your game will look like on difference screens with different aspect ratios.

We try to support it in next version, v3.4.

1 Like