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:
- Make a copy of the template folder in Finder and eventually rename the new folder
- Open the .xcodeproj in Xcode.
- 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:
@interface StartLayer : CCLayer
+(CCScene *) scene;
Change StartLayer.m to:
+(CCScene *) scene
CCScene *scene = [CCScene node];
StartLayer *layer = [StartLayer node];
[scene addChild: layer];
if( (self=[super init]) )
// initialization code here
Change the import line in AppDelegate.m
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.