Developing game is a real fun. Recently I was working with cocos2d-android engine. I think it’s a very cool game developing engine. In this text I will introduce you to the essential building block of cocos2d-android game engine.
The Cocos2d Scene
A scene is a more or less independent piece of game workflow. You may call it screen or stage. Your game may have multiple scenes. For example – Splash screen, Menu, Level, High scores screen etc. Scene is implemented by CCScene class.
In the most cases CCScene doesn’t contain any game specific code and is rarely sub-classed. Normally it holds children which are derived from CCLayer which contain in turn contain the individual game objects. Most often Scene is created inside CCLayer Object in a static method
Director
The director is the component which takes care about going back and forth between scenes. The Director is a shared object. It is implemented singleton. It knows everything, like which scene is currently active etc. More generally it holds stack of scene. Any replacement of scene is made by Director. It is implemented by CCDirector class
Layer
Sometimes you need more than one layer in your scene. In that case you can add more CCLayer object to your scene. It helps you organize the scene. For example – background, top, bottom etc. Layers are basically a grouping concept. Some layers- CCLayer: very basic layer of cocos2d.
CCColorLayer: A solid color rectangle, it works as CCLayer but only contains a background color.
CCMultiplexLayer: A group of layers where only one is seen at a time.
CCMenu: Implemets simple menu
Sprite
A cocos2d sprite is like any other computer sprite. It is a 2D image that can be moved, rotated, scaled, animated etc. CCSprite is implementation of it. It can have other sprite as children. When parent is transformed, all the other children are transformed as well. Creating a sprite is very simple. You have to add the image file to the asset folder of your project. And the code is very straight forward
The Cocos2d Scene
A scene is a more or less independent piece of game workflow. You may call it screen or stage. Your game may have multiple scenes. For example – Splash screen, Menu, Level, High scores screen etc. Scene is implemented by CCScene class.
In the most cases CCScene doesn’t contain any game specific code and is rarely sub-classed. Normally it holds children which are derived from CCLayer which contain in turn contain the individual game objects. Most often Scene is created inside CCLayer Object in a static method
Director
The director is the component which takes care about going back and forth between scenes. The Director is a shared object. It is implemented singleton. It knows everything, like which scene is currently active etc. More generally it holds stack of scene. Any replacement of scene is made by Director. It is implemented by CCDirector class
Layer
Sometimes you need more than one layer in your scene. In that case you can add more CCLayer object to your scene. It helps you organize the scene. For example – background, top, bottom etc. Layers are basically a grouping concept. Some layers- CCLayer: very basic layer of cocos2d.
CCColorLayer: A solid color rectangle, it works as CCLayer but only contains a background color.
CCMultiplexLayer: A group of layers where only one is seen at a time.
CCMenu: Implemets simple menu
Sprite
A cocos2d sprite is like any other computer sprite. It is a 2D image that can be moved, rotated, scaled, animated etc. CCSprite is implementation of it. It can have other sprite as children. When parent is transformed, all the other children are transformed as well. Creating a sprite is very simple. You have to add the image file to the asset folder of your project. And the code is very straight forward