首页 > 代码库 > Cocos2d-x学习笔记(六)Label字体控制
Cocos2d-x学习笔记(六)Label字体控制
这里要注意.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字体控制
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。