Cocos2D iPhone Framework
Already heard a lot about it, so today I made my first try of this iPhone game library. Cocos2d iPhone is a port of the Cocos2d python library to Objective-C. A lot of games have used this library, see here: http://www.cocos2d-iphone.com/forum/forum/1
Firstly, you need to set up a standard iPhone project in Xcode. Since Cocos2d iPhone is basically based on OpenGL ES, we don’t need any view container in our application, just choose the “Window-Based Application”. We name the project “FoldCut”.

Next step is to download Cocos2d iPhone from Google Code, the current version is cocos2d-iphone-0.8-beta.tar.gz. Extract the file and add the subdirectory cocos2d to the new project. Make sure that you check the option “Copy items into destination group’s folder (if needed)” before click “Add”. Cocos2d make use the frameworks OpenGLES and Quartz Core internally, so you need to add these two frameworks to the project too : Right click the project -> Add -> Existing Frameworks …
Now you build your project, it should go fine. We didn’t use anything of the library. The build is just to compile the Cocos2D library itself.
When Xcode created the project from the template, it added a MainWindow.xib and uses this NIB to create the main window. For a Cocos2D project we don’t actually need them. So we make some changes in main.m and FoldCut-Info.plist.
int main(int argc, char *argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"FoldCutAppDelegate");
[pool release];
return retVal;
}
Remove the entry “Main nib file base name”, add a new entry “Status bar is initially hidden” and set it to checked like followed.

Then modify FoldCutAppDelegate.m file to initialize the main window.
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
// Create a full screen window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Cocos2D Director
[[Director sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
[[Director sharedDirector] attachInWindow:window];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
Build and Go, and the Crash ! With the Xcode Debugger, you’ll find somewhere in the framework, an image file “fps_images.png” is loaded and used. This file can be located in directory “cocos2d-iphone-0.8-beta/Resources/Images”, get it and add it to the project. Build and Go again, this time the app should work.
About this entry
You’re currently reading “Cocos2D iPhone Framework,” an entry on Modern Computer
- Published:
- July 2, 2009 / 10:30 pm
- Category:
- Uncategorized
- Tags:
- iPhone
No comments yet
Jump to comment form | comments rss [?]