Displaying some text on the screen using the Framework Cocos2D
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 he开发者_Go百科lp me on this topic.
The simplest way would be to create a CCLabelTTF
node and add it to your scene.
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 !
精彩评论