Wednesday, 4 January 2012

Dev: Using Cocos2D with Automatic Reference Counting (ARC) in XCode 4

Cocos2D doesn't make use of the Automatic Reference Counting (ARC) features now available in the new compiler (with XCode 4,) and it's a little fiddly to make it work.

We cracked it, with a little help from Tiny Tim Games (do feel free to follow their tutorial instead.) We thought we'd give you a quick step-by-step guide to getting it working, (it's also for future us too.)

Get Cocos2D
Grab this branch of the project: https://github.com/cocos2d/cocos2d-iphone.
  • Either download it, or type this into Terminal (into a sensible directory): git clone https://github.com/cocos2d/cocos2d-iphone.git
  • It's pretty massive (over 50MB), so do it just before you need a cup of tea
Create a new Blank Project
Create a new blank project, and be sure to check (turn on) the "Use Automatic Reference Counting" option.

Do something that requires Cocos2D in your new project
  • Open your AppDelegate.m file and add an import for cocos2d.h
  • Add this snippet of code to the 'application:didFinishLaunchingWithOptions:' method:

CCScene *scene = [[CCScene alloc] init];

[scene cleanup];

  • Try to build your project, notice that it fails with an 'Apple Mach-O Linker" error. This is because it's trying to use CCScene class which we haven't added a reference for yet.
Include Cocos2D
XCode supports 'cross-project referencing', and this is the best way to include Cocos2D. In Finder, locate the 'cocos2d-ios.xcodeproj' file, and drag it into your new project.
  • You should see that the project gets included wholesale (literally like a sub-project) in XCode.
  • I then like to drag the Cocos2D project into the Frameworks folder to keep things clean.
Link to Cocos2D and tweak some settings
  1. Select your project in XCode
  2. Choose the "Build Phases" tab
  3. Expand the "Link Binary With Libraries (x items)" section
  4. Click the + symbol to add another library
  5. From the "Workspace" section, select 'libcocos2d.a"
  6. Click "Add"
  7. If it's red, don't worry, it has still worked
  8. Repeat the same for the following frameworks: OpenGLES, libz, QuartzCore
  9. NOTE: You will likely need to add more frameworks as you use more features of Cocos2D, but for now, this works.
Then nip over to the "Build Settings" tab:
  1. Set "Always Search User Paths" to "YES"
  2. Add the Cocos2D project path to the "User Header Search Paths" property, ensuring it's recursive
  3. In my case, I set it to: "/Users/matryer/Work/cocos2d/**"
Build again
  • Build your project again and notice that all works
Now you can go ahead and build your game, we look forward to playing it :-)

Wednesday, 14 December 2011

Switch City

Switch City iTunes Logo

Switch City is our first ever app in the App Store, and it's our first ever game as developers. We are very excited to see the reaction it gets as people play it.  Oh and it just went live in the App Store!

The game is simple, keep the switches turned ON for as long as possible.  As switches short out, the city starts to lose power - but it slowly rebuilds provided all switches remain on.  Meanwhile, there are a few special things to collect in the clouds, and a few nasty ones to help or hinder you while you keep the lights on in Switch City.

We wanted to build a very simple (little), but highly addictive (mighty) game that's easy to pick up but difficult to master... and with Game Center integration, we can't wait to see some of the scores people can get.

We decided to integrate with Game Center because we hope people will start competing right away, which will hopefully drive more downloads and awareness for our little company.

We wanted to make the app free to download so we included iAd's to hopefully generate some revenue to cover costs and allow us to make more games and apps, though we have read mixed reviews of the amount of revenue you can generate - it's something we are going to be quite agile about.

The app has a festive bent for obvious reasons (remember, it just went live - check the date if you're reading this from the future and you'll see what I mean... and also, please let us know what the lottery numbers are if you can.) although the icon above is the non-Christmas version (which we'll release next year.)

Any feedback that comes in over the next few days will be considered very carefully and we might plan to push an update out before Christmas, to give people a little extra.  We are however constrained by Apple's cut-off date (currently 22nd December) so we might not have time.

Meanwhile, please enjoy the game and let us know what you think on our Facebook page,

Merry Christmas
Mat and Chris

Our mission

Our mission is to make little but awesome games, apps and things that people can touch, play with, get angry with and fall in love with.