Installing Cocos2D-x with Xcode


With Cocos2d-iphone / -swift / -spritebuilder / -objc losing its cross platform support, anyone using this great API will unfortunately be stuck releasing for iOS only.

This effectively means, that if you want to release for Android also, you will have to scrap Objective-C as your language of choice.

However, there is also good news.

For anyone who has been using Objective-C flavoured Cocos2D, migrating to Cocos2D-x will be a much smaller step than most expect. You obviously will have to code in C++ instead of Obj-C, but at the end of the day, the difference is negligible, and everything will be working in Xcode as you were used to, once you get the hang of the C++ syntax.

One of the biggest difference might actually be, that C++ does not have anything like ARC. Personally I have never been a big fan, and always thought it was a mistake that we converted to ARC. While it will be easier for the newcomer, anyone serious about making a game or an application, should understand the fundamentals of memory-handling anyways, and failing to understand when to use weak and strong, will lead to just as much grief, as not understanding retain and release.

I will write a tutorial on basic memory handling in C++ later.

First for downloading and installing cocos2d-x.

The cocos2d-x site is located here  It works pretty much as the -objc site, with a forum, download section, and various kind of information. Main difference being, that it is much bigger.

You start by downloading the latest version of cocos2d-x here

A long time ago, I created a Cocos2D folder in my Library folder where I place all my cocos2d stuff, so in my case the download ended up in

Library/Cocos2D/cocos2d-x-3.7

When done, open terminal, and change folder to where you placed cocos2d-x. Then run the script

./setup.py

This will install everything you need to start using cocos2d-x with Xcode. The setup script will ask you for three paths, but these are for Android only, so simply ignore them for now. I will add a tutorial on how to port to Android later.

When the setup script completes, it will ask you to run a command starting with “source”. Simply copy the line in terminal, and execute it.

From here, you are ready to start creating -x based applications.

When you ran ./setup.py, you also installed a command line interface named cocos. You use this for various tasks, including creating new projects. To do this, you use the syntax cocos new.

There are many ways to customize this, but the simplest way is to open terminal, and switch to the folder where you want your project to be created. You then use the command

cocos new <app_name> -p <package_name> -l cpp

If the app_name contains spaces, wrap it in quotes, and te package name is most often the backwards web notation you also use in iOS.

Ex com.mycompany.mygame

cocos will then create a cross platform project, containing everything you need to publish your game on multiple platforms. For now we will only concentrate on iOS, so open the newly created folder, and navigate to the sub folder proj.ios_mac. Here you will find your normal xcode project, which you can open, compile and run in the simulator, just as you are used to.

And that really is all there is to it : )