码迷,mamicode.com
首页 > 其他好文 > 详细

Cocos2d-x学习笔记(六)Label字体控制

时间:2015-01-03 23:50:23      阅读:312      评论:0      收藏:0      [点我收藏+]

标签:

这里要注意.fnt文件可通过BMFont工具进行创建,该代码于init函数中:

auto label1 = Label::createWithSystemFont("Hello World1", "Arial", 24);
    label1->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 100));
    this->addChild(label1, 1);

    auto label2 = Label::createWithTTF("Hello World2", "fonts/Marker Felt.ttf", 24);
    label2->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 200));
    this->addChild(label2, 1);

    auto label3 = Label::createWithBMFont("fonts/t2.fnt", "Hello World3");
    label3->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 300));
    this->addChild(label3, 1);

    TTFConfig ttfConfig("fonts/Marker Felt.ttf", 24, GlyphCollection::DYNAMIC);
    auto label4 = Label::createWithTTF(ttfConfig, "Hello World4");
    label4->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 400));
    this->addChild(label4, 1);

    ttfConfig.outlineSize = 4;
    auto label5 = Label::createWithTTF(ttfConfig, "Hello World5");
    label5->setPosition(Vec2(origin.x + visibleSize.width/2, origin.y + visibleSize.height - 500));
    // Enable shadow for the label
    label5->enableShadow(Color4B(255,255,255,128), Size(4, -4));
    label5->setColor(Color3B::RED);
    this->addChild(label5, 1);

运行结果如下:

技术分享

Cocos2d-x学习笔记(六)Label字体控制

标签:

原文地址:http://www.cnblogs.com/AmitX-moten/p/4200047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!