How do I add a line of text to the screen?
1. Create a label commonly used method summary:
. :: A the Label the Create () // // is declared to have been rejected
b. Label::createWithSystemFont()
c. Label::createWithTTF()
2. Summary tag added effects (listed in order to construct a consistent source order):
a. enableGlow
b. enableOutline
c. enableShadow
d. enableItalics
e. enableBold
f. enableUnderline
g. enableStrikethrough
3. The label may also set the color:
setColor
Example Effect:
Sample code:
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 )); // shadow label_03-> enableItalics (); // italic label_02-> enableBold (); // bold label_06-> enableUnderline () ; // underscore label_07-> enableStrikethrough (); // delete the line label_07-> setColor (Color3B :: YELLOW); // set the color