Cocos2d-x_CCLabelProtocol(标签类)

Cocos2d-x引擎当中为开发者提供了专门的用于绘制文字的类以及方法。引擎中用于处理文字的三个类分别是:CCLabelAtlas、CCLabelBMFont和CCLabelTTF,这三个类都是通过不同的方式来显示文字的。


1、CCLabelTTF:

/* CCLabelTTF类的创建函数 */

// 创建TTF标签对象,参数为显示文字内容、字体名称和字体尺寸
static CCLabelTTF *create(const char *string, const char *fontName, float fontSize);
// 创建TTF标签对象,参数为显示文字内容、字体名称、字体尺寸、标签尺寸、文字水平对齐方式
static CCLabelTTF *create(const char *string, const char *fontName, float fontSize,
                          const CCSize &dimensions, CCTextAlignment hAlignment);
// 创建TTF标签对象,参数为显示文字内容、字体名称、字体尺寸、标签尺寸、文字水平对齐方式、文字垂直对齐方式
static CCLabelTTF *create(const char *string, const char *fontName, float fontSize,
                          const CCSize &dimensions, CCTextAlignment hAlignment,
                          CCVerticalTextAlignment vAlignment);

void HelloWorld::showFont(const char *pFont)
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCSize blockSize = CCSizeMake(size.width/3, 200);
    float fontSize = 26;
    
    CCLabelTTF *left = CCLabelTTF::create("alignment left", pFont, fontSize, blockSize, kCCTextAlignmentLeft, kCCVerticalTextAlignmentTop);
    CCLayerColor *leftColor = CCLayerColor::create(ccc4(100, 100, 100, 255), blockSize.width, blockSize.height);
    
    leftColor->ignoreAnchorPointForPosition(false);
    
    left->setAnchorPoint(ccp(0, 0.5));
    leftColor->setAnchorPoint(ccp(0, 0.5));
    
    left->setPosition(ccp(0, size.height/2));
    leftColor->setPosition(left->getPosition());
    
    this->addChild(leftColor,-1);
    this->addChild(left, 0);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值