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.
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.
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 !
The simplest way would be to create a
CCLabelTTF
node and add it to your scene.