Game Development Reference
If this particular class doesn't derive from CCScene, Kobold2D will create the CCS-
cene object automatically behind the scenes.
Moving on to the -(id) init method of the HelloWorldLayer class, that's
where the code starts to deviate between cocos2d, Kobold2D, and each individual pro-
ject template. There are some commonalities though. Listing 2-2 represents a minim-
al init code for a "Hello World" app. The actual code in the project differs, but
you'll definitely see a CCLabelTTF being added in the project you created earlier.
Notice something that might seem odd: self is assigned the return value from the
init message sent to the super object in the call to self = [super init] .
If you come from a C++ background, you'll shudder in pain looking at this. Don't get
too upset; it's all right. It simply means that in Objective-C you have to manually call
the superclass's init method. There's no automatic call to the parent class. And you
do have to assign self the return value of the [super init] message because
it might return nil .
Creates and Adds a “Hello World” Label
if ((self = [super init]))
// create and initialize a label
CCLabelTTF* label = [CCLabelTTF labelWithString:@"Hello World"
// get the window (screen) size from CCDirector
CGSize size = [[CCDirector sharedDirector] winSize];
// position the label at the center of the screen
label.position = CGPointMake(size.width / 2, size.height / 2);
// add the label as a child to this Layer
The CCLabelTTF class draws text on the screen using a TrueType font.