How to Use ARC Templates for Cocos2D v2

Cocos2d is an open source 2D game framework. The framework is ported to multiple platform, including for iOS "cocos2d for iPhone". In the past it used to be quite an hassle to enable ARC into your cocos2d projects. However, the following guidelines describes how to enable ARC into your project. Steffen Itterheim, the author of the "Learn Cocos2D" book has made different ARC-enabled project templates available for download at GitHub.

Download and unpack the templates. The next templates are made available for iOS in combinitation with cocos2d-v2.

  • cocos2d-2.x-ARC-iOS - plain template
  • cocos2d-2.x-Box2D-ARC-iOS - with Box2D physics engine
  • cocos2d-2.x-Chipmunk-ARC-iOS - with Chipmunk physics engine

To create a new project, proceed with the following steps:

  1. Make a copy of the template folder in Finder and eventually rename the new folder
  2. Open the .xcodeproj in Xcode.
  3. Rename the project in the Project Navigator by left-clicking the project name.

The folowing dialog box appears.

To rename all underlying items click Rename.

The project contains a simple HelloWorldLayer.h and Helloworld.m file. Build and Run the project.

To start with a clean Framework, make the following adjustments.

Create a new Objective-C class, file StartLayer, subclass of CCLayer.

Change StartLayer.h to:

#import "CCLayer.h" 
#import "cocos2d.h"

@interface StartLayer : CCLayer

+(CCScene *) scene;


Change StartLayer.m to:

#import "StartLayer.h"
#import "AppDelegate.h"

@implementation StartLayer

+(CCScene *) scene
CCScene *scene = [CCScene node];
StartLayer *layer = [StartLayer node];
[scene addChild: layer];

return scene;

-(id) init
if( (self=[super init]) )
// initialization code here
return self;


Change the import line in AppDelegate.m

#import "StartLayer.h"

in application.didFinishLaunchingWithOptions change the second-last line to

[director_ pushScene: [StartLayer scene]];

Finally, remove the HelloWorldLayer.m and HelloWorldLayer.h files from the project. And that's it, a clean cocos2d project ready to be filled with all you can imagine.