Displaying some text on the screen using the Framework Cocos2D

954 views Asked by At

I want to display a text on the screen using the framework Cocos2D.

I'm thinking off using the draw method. But I don't know the exact way of doing that.

I would be glad if anyone could help me on this topic.

2

There are 2 answers

0
Marco Mustapic On

The simplest way would be to create a CCLabelTTF node and add it to your scene.

0
Andy M On

Here is a possible way :

This code is within a simple scene class :

// on "init" you need to initialize your instance
-(id) init
{
    // always call "super" init
    // Apple recommends to re-assign "self" with the "super's" return value
    if( (self=[super init]) ) 
    {
        // create and initialize a Label
        CCLabelTTF *label = [CCLabelTTF labelWithString:@"Hello World" fontName:@"Marker Felt" fontSize:64];

        // ask director for 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;
}

Hope it can help you !