iPhone SDK comes with OpenGL and Quartz 2d framework to create animations and effects. Unfortunately, these frameworks are quite challenging to learn. Cocos2d framework for the iPhone comes as a beam of hope which provides capabilities to create slick looking effects and animations with minimal effort. In this article we are going to give an introduction on how to use the Cocos2d library for iPhone game development.
Downloading Cocos2d for the iPhone:
The first step towards Cocos2d awesomeness is to download the Cocos2d framework for the iPhone. You can use the following URL to download the Cocos2d framework.
Cocos2d for the iPhone
Install the framework after downloading it. The version 0.8.1 and later will automatically install the Cocos2d templates which you can use in XCode to quickly setup your Cocos2d project. Now start your XCode and you will see the Cocos2d template as shown in the screenshot below:
Since, we are creating Cocos2d application select the "Cocos2d Application" template. This will create the basic skeleton for the application. You can run the application and it will greet you with a "Hello World" page as shown in the screenshot below:
Now that you have got the simple application to run let's move to some basics about how Cocos2d framework works.
Basic Understanding of Cocos2d:
Consider scenes as screens. One scene can be the main menu, second can be the game itself, third can be the game over scene, forth can be high score scene etc.
Each scene can have many different layers on it. Layers in Cocos2d work like layers in Photoshop. The background can be on a separate layer then the foreground. When all the layers are in place correctly on top of each other they form a scene.
Sprites are the actors in Cocos2d environment. You can perform different actions on Sprites which includes moving, rotating, fading, scaling etc.
Box2d is an awesome framework for creating block applications. Tetris is one of the good examples of the Box2d application.
ChipMuck is the physics framework. Physics may sound boring but all cool games these days have elements of physics in them. If you want to create an awesome game then ChipMuck is the physics framework to use.
Cocos2d library is a very powerful library to create iPhone games. You can achieve really complicated effects easily with Cocos2d library. The next article will focus on how to use scenes, layers and sprites to create an actual application.