0

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.

Andy M
  • 5,945
  • 7
  • 51
  • 96
Rocker
  • 1,467
  • 5
  • 14
  • 20

2 Answers2

0

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 !

Andy M
  • 5,945
  • 7
  • 51
  • 96
0

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

Marco Mustapic
  • 3,879
  • 1
  • 21
  • 20