开发者

Displaying some text on the screen using the Framework Cocos2D

开发者 https://www.devze.com 2022-12-12 05:24 出处:网络
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 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 !

0

精彩评论

暂无评论...
验证码 换一张
取 消