### Cocos2d-x vs. Cocos2d iPhone / Swift? Cocos2d iPhone is a also a free game engine. It differs from cocos2dx in that it is written in the Objective C programming language and only supports the iOS and Mac platforms. If you've used Cocos2d iPhone, it's likely you enjoyed the experience. The Cocos2d API is simple and powerful. With a couple lines of code you can bring a few images and sounds to life using actions and create your own vibrant world. Cocos2d-x takes all that beautiful API power and makes it portable using C++. It unlocks you, the developer, and enables you to choose which platforms you want to develop on and deploy to. ### Why isn't Cocos2d iPhone portable? Cocos2d iPhone isn't portable because it's written in Objective C, which isn't supported natively on some platforms, and relies heavily on Foundation Kit and Apple's Cocoa. Essentially, it's glued to the Mac/iOS platform. While some attempts have been made to get Cocos2d iPhone compiling for Android with upgraded NDKs and open-source implementations of Foundation Kit like [GNUstep][2] or [Cocotron][3], most of these attempts end up becoming resemblant of cocos2d-x. They even have to use some of cocos2dx's code to get things like touch input and sound effects to work. So why not just start writing games in C++ with cocos2d-x? It's had portability in mind the whole time. ### C++: A Game Dev's Best Friend If you've been a game developer for awhile, you already know all about C++. In the game dev world, C++ is one of the [most popular languages][4]. C++ is fast, portable, time-tested, supported natively on most platforms, has many libraries available and most programmers have some experience with it. Recently, C++ has been updated to versions [C++11][5] and [C++14](//en.wikipedia.org/wiki/C%2B%2B14). There's a few bits of syntactic sugar that will make your programming life easier. The `auto` keyword, for example, is handy as a hammer in a field of nails and lambda functions are something you won't be able to live without. C++ has been around forever, it's too useful to ever go away, it continues to get better, and it enables your app to run on the widest array of platforms. These are good reasons to choose it for your next game or app project. ### The Amazon Appstore & Google Play If you release your game solely on the Apple App Store, you could be [missing out on over 50%][6] of potential sales via the Amazon Appstore, Google Play or Steam. Most developers want to get the full 100% of their game's potential, hence the ever-increasing popularity of the cocos2d-x cross-platform game engine. ### Lua & Javascript Support Cocos2d-X has built-in bindings for the Lua and Javascript languages, making it possible for you to script some -- if not all -- of your game code. You write the lower-level stuff in C++ and the higher-level stuff in your choice of scripting language. The Cocos2d-X team has even released a completely [Javascript-based version of Cocos2d][7] called Cocos2D JS that combines Cocos2D-HTML5 for browsers and Cocos2D-X with Javscript bindings for mobile and desktop. ### Q: How current is Cocos2d-X? Since 2012, the Cocos2d family has been released in a coordinated fashion. Cocos2d X, Cocos2d iPhone and Cocos2d JS/HTML5 are all released simultaneously. ### Q: Deploying to Windows Phone? Thanks to a recent contribution from Microsoft, Cocos2d X now supports Windows Phone. ### Q: How much platform-specific code? You might be wondering how much platform-specific code has to be written for your game to deploy to many different platforms. The answer is that every platform has their own project files and their own main function or app launching code. Once you get past that little bit, you're in pure Cocos2d-X C++ land, where all your game code is exactly the same. ### Q: In-app purchases? Game center? What about in-app purchases and Game Center? Well, the answer is that those things are platform-specific. In the case of Game Center, it's easy enough to replace it with something portable like [Google Play game services][8]. When it comes to in-app purchases, you can either go with [Soomla][9] or program store-specific in-app purchasing for the Apple App Store, Google Play and Amazon App Store individually. ### Q: Android fragmentation? Multiple screens resolutions and ratios? What about the fragmentation amongst Android devices? With so many screen resolutions and ratios, how does one write a single game code base that handles all those devices? It's actually really easy. You just need multiple tiers of art assets and some flexible game code. For example, you might have a sprite that is 100 pixels wide by 100 pixels tall on standard-definition devices. If that file is called "sd/Sprite.png" then you just need to output a 200x200 version called "hd/Sprite.png" and a 400x400 version called "hdr/Sprite.png", then instruct Cocos2d-X to use either the "sd", "hd" or "hdr" folder depending on the resolution. Combine that magic with some flexible positioning of art resources on the screen based on the dimensions of the current display, and you've got a single code base that plays well and looks crisp on any device. The alternative solution is to use `Director::setDesignResolution` with your highest supported resolution (for example 2048x1536) and design your graphics around that. When using `setDesignResolution`, Cocos2D-X will automatically scale your graphics to fit the current device's screen. ### Q: Analytics? Extensions? It's important to gather data on how your game is being played, so how do you do that in a cross-platform way? Well, there's a [Flurry plugin][10] or this [C++ Flurry Analytics wrapper][11]. So you can start gaining insight into how your players are engaging with your game. ### Conclusion So there you have it. An overview of Cocos2d-X: one of the best, free, cross-platform game engines around. It's portable and it's got everything you need to start rapidly developing multi-platform games and apps. [1]: //cocos2d-x.org/ [2]: //www.gnustep.org/information/aboutGNUstep.html [3]: //www.cocotron.org/ [4]: //gamedev.stackexchange.com/questions/11069/competing-with-c-for-games-programming [5]: //www.informit.com/articles/article.aspx?p=1910142 [6]: //blog.flurry.com/bid/83604/For-Generating-App-Revenue-Amazon-Shows-Google-How-to-Play [7]: //www.cocos2d-x.org/wiki/Cocos2d-JS [8]: //www.theverge.com/2013/5/15/4327880/google-announces-android-game-center-competitor [9]: //soom.la/ [10]: //www.cocos2d-x.org/wiki/Plugin-X [11]: //github.com/diwu/AnalyticX [12]: /c-game-development/
Got questions? Leave a comment below. You can also subscribe to be notified when we release new chapters.