Introduction to Cocos2D for iPhone/iPad

Hello ! All, This would be my first post for Cocos2D game development.

Using this post, I am going to describe following things.

  1. Downloading Cocos2D framework
  2. Installing project templates for Cocos2D
  3. Understanding HelloWorld Application of Cocos2D

Downloading Cocos2D framework

To download Cocos2D framework click here.


Installing Project Template.

  • Extract the downloaded Cocos2D framework.
  • Open the Folder.
  • Follow the steps as illustrated in image.
Installing Cocos2D Project Template

Installing Cocos2D Project Template


Understanding HelloWorld Application.

Application Delegate file

Understanding cocos2d basics - 1 

  1. Create a window based on the size of device’s screen size.
  2. Create an instance of viewController class.
  3. Create a n EAGLView/OpenGL view
  4. Have an access to singleton object of CCDirector & then assign EAGLView’s instance’s reference to director.
  5. Check whether ratina display is supported or not.
  6. Set frames per second.
  7. Set YES/NO to display frame numbers.
  8. Assign EAGLView’s instance to viewController’s view.
  9. Add ViewController’s view to window & make visible window.
  10. Texture related settings.
  11. Remove flicker if your game/application is supporting only landscape orientation.
  12. Invoke the scene of HelloWorldLayer scene.

Hello World Layer file

+(CCScene *) scene
{
	// 'scene' is an autorelease object.
	CCScene *scene = [CCScene node];
	// 'layer' is an autorelease object.
	HelloWorldLayer *layer = [HelloWorldLayer node];
	// add layer as a child to scene
	[scene addChild: layer];
	// return the scene
	return scene;
}

// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init])) {
		// create and initialize a Label
		CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];
		// ask director the the window size
		CGSize size = [[CCDirector sharedDirector] winSize];
		// position the label on the center of the screen
		label.position =  ccp( size.width /2 , size.height/2 );
		// add the label as a child to this Layer
		[self addChild: label];
	}
	return self;
}

The comments within code describes the code. However, view following video to understand more precisely.


Video Demostration

Leave a Reply

Your email address will not be published. Required fields are marked *