Game Development Reference
In-Depth Information
The CCLayer class does very little by itself other than allow touch and accelero-
meter input. You'll normally use it as the first class added to the CCScene , simply be-
cause most games use at least simple touch input. Strictly speaking CCLayer is not
needed to layer objects—you can achieve the same effect with CCNode or any other
class derived from CCNode .
If you open the HelloWorldLayer.h header file, you'll see that the Hel-
loWorldLayer class is derived from CCLayer . So where does the CCS-
cene class come into play?
Because CCScene is merely an abstract concept, the default way of setting up a
scene in cocos2d has always been to use a static initializer +(id) scene in your
class. This method creates a regular CCScene object and then adds an instance of
the HelloWorldLayer class to the scene. In almost all cases, that's the only place
where a CCScene is created and used. The following is a generic example of the
+(id) scene method:
+(id) scene
{
CCScene *scene = [CCScene node];
id layer = [HelloWorldLayer node];
[scene addChild:layer];
return scene;
}
First, a CCScene object is created using the class method +(id) node of the
CCScene class. Next, the HelloWorldLayer class is created using the same
+(id) node method and then added to the scene. The scene is then returned to the
caller.
In a Kobold2D project,you may notice that the +(id) scene method is absent.
You can use the config.lua setting FirstSceneClassName to instruct Ko-
bold2D to run this particular class as the first scene:
FirstSceneClassName = "HelloWorldLayer",
Search Nedrilad ::




Custom Search