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

Cocos2dx__标签

时间:2020-03-05 01:21:36      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:划线   span   osi   删除线   com   conf   line   sys   strong   

如何向屏幕加入一行文字?

 

1. 常用创建标签方法汇总:
  a. Label::create()  // // 被声明为已否决

  b. Label::createWithSystemFont()

  c. Label::createWithTTF()

 

2. 标签加入特效汇总(列出顺序与源码构建顺序一致):

  a. enableGlow

  b. enableOutline

  c. enableShadow

  d. enableItalics

  e. enableBold

  f. enableUnderline

  g. enableStrikethrough

 

3. 标签还可以设置颜色:

  setColor

 

示例效果:

    技术图片

 

 

示例代码:

auto layerLabels = Layer::create();
this->addChild(layerLabels, 1);

auto label_01 = Label::create("I‘m the first label", "Microsoft YaHei UI", 36);        // 被声明为已否决
label_01->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 1 - label_01->getContentSize().height / 2);
layerLabels->addChild(label_01);

auto label_02 = Label::createWithSystemFont("I‘m the first label", "Microsoft YaHei UI", 36);
label_02->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 2 - label_02->getContentSize().height / 2);
layerLabels->addChild(label_02);

auto label_03 = Label::createWithSystemFont("I‘m the second label", "Arial", 36);
label_03->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 3 - label_03->getContentSize().height / 2);
layerLabels->addChild(label_03);

auto label_04 = Label::createWithTTF("I‘m the third label", "fonts\\arial.ttf", 36);
label_04->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 4 - label_04->getContentSize().height / 2);
layerLabels->addChild(label_04);

TTFConfig labelConfig("fonts\\Marker Felt.ttf", 36);
auto label_05 = Label::createWithTTF(labelConfig, "I‘m the fourth label");
label_05->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 5 - label_05->getContentSize().height / 2);
layerLabels->addChild(label_05);

auto label_06 = Label::createWithTTF(labelConfig, "I‘m the fourth label");
label_06->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 6 - label_06->getContentSize().height / 2);
layerLabels->addChild(label_06);

auto label_07 = Label::createWithTTF(labelConfig, "I‘m the fourth label");
label_07->setPosition(visibleSize.width / 2, visibleSize.height - 50 * 7 - label_07->getContentSize().height / 2);
layerLabels->addChild(label_07);

// Outline 和 Glow 不能共存
label_06->enableGlow(Color4B::RED);                    // 发光
label_05->enableOutline(Color4B::RED, 2);            // 边框
label_04->enableShadow(Color4B::RED, Size(2, -2));    // 阴影
label_03->enableItalics();                            // 斜字体
label_02->enableBold();                                // 粗体
label_06->enableUnderline();                        // 下划线
label_07->enableStrikethrough();                    // 删除线
label_07->setColor(Color3B::YELLOW);                // 设置颜色

 

Cocos2dx__标签

标签:划线   span   osi   删除线   com   conf   line   sys   strong   

原文地址:https://www.cnblogs.com/teternity/p/Cocos2dx__Label.html

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