Cocos2dx__标签

Posted teternity

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Cocos2dx__标签相关的知识,希望对你有一定的参考价值。

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

 

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__标签的主要内容,如果未能解决你的问题,请参考以下文章

这些 C++ 代码片段有啥作用?

MYBATIS05_ifwherechoosewhentrimsetforEach标签sql片段

cocos2dx游戏--欢欢英雄传说--为敌人添加移动和攻击动作

Cocos2dx__精灵创建

cocos2dx 3.x(加载网络自定义头像)

cocos2dx 场景切换