本文整理汇总了C++中Text::addChild方法的典型用法代码示例。如果您正苦于以下问题:C++ Text::addChild方法的具体用法?C++ Text::addChild怎么用?C++ Text::addChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Text
的用法示例。
在下文中一共展示了Text::addChild方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addUnderline
void ITools::addUnderline(void* vv)
{
Text* tt = (Text*)vv;
Color4B color = tt->getTextColor();
DrawNode* drawLine = DrawNode::create();
drawLine->drawLine(Vec2(0,0), Vec2(tt->getContentSize().width,0), Color4F((float)color.r/255, (float)color.g/255, (float)color.b/255, (float)color.a/255));
drawLine->setPosition(Vec2(0,2));
tt->addChild(drawLine);
}
示例2: setPropsWithFlatBuffers
void TextReader::setPropsWithFlatBuffers(cocos2d::Node *node, const flatbuffers::Table *textOptions)
{
Text* label = static_cast<Text*>(node);
auto options = (TextOptions*)textOptions;
bool touchScaleEnabled = options->touchScaleEnable() != 0;
label->setTouchScaleChangeEnabled(touchScaleEnabled);
std::string text = options->text()->c_str();
label->setString(text);
int fontSize = options->fontSize();
label->setFontSize(fontSize);
std::string fontName = options->fontName()->c_str();
label->setFontName(fontName);
Size areaSize = Size(options->areaWidth(), options->areaHeight());
if (!areaSize.equals(Size::ZERO))
{
label->setTextAreaSize(areaSize);
}
TextHAlignment h_alignment = (TextHAlignment)options->hAlignment();
label->setTextHorizontalAlignment(h_alignment);
TextVAlignment v_alignment = (TextVAlignment)options->vAlignment();
label->setTextVerticalAlignment((TextVAlignment)v_alignment);
bool fileExist = false;
std::string errorFilePath = "";
auto resourceData = options->fontResource();
std::string path = resourceData->path()->c_str();
if (path != "")
{
if (FileUtils::getInstance()->isFileExist(path))
{
fileExist = true;
}
else
{
errorFilePath = path;
fileExist = false;
}
if (fileExist)
{
label->setFontName(path);
}
else
{
auto alert = Label::create();
alert->setString(__String::createWithFormat("%s missed", errorFilePath.c_str())->getCString());
label->addChild(alert);
}
}
bool outlineEnabled = options->outlineEnabled();
if (outlineEnabled)
{
auto f_outlineColor = options->outlineColor();
if (f_outlineColor)
{
Color4B outlineColor(f_outlineColor->r(), f_outlineColor->g(), f_outlineColor->b(), f_outlineColor->a());
label->enableOutline(outlineColor, options->outlineSize());
}
}
bool shadowEnabled = options->shadowEnabled();
if (shadowEnabled)
{
auto f_shadowColor = options->shadowColor();
if (f_shadowColor)
{
Color4B shadowColor(f_shadowColor->r(), f_shadowColor->g(), f_shadowColor->b(), f_shadowColor->a());
label->enableShadow(shadowColor, Size(options->shadowOffsetX(), options->shadowOffsetY()), options->shadowBlurRadius());
}
}
// Save node color before set widget properties
auto oldColor = node->getColor();
auto widgetReader = WidgetReader::getInstance();
widgetReader->setPropsWithFlatBuffers(node, (Table*)options->widgetOptions());
// restore node color and set color to text to fix shadow & outline color won't show correct bug
node->setColor(oldColor);
auto optionsWidget = (WidgetOptions*)options->widgetOptions();
auto f_color = optionsWidget->color();
Color4B color(f_color->r(), f_color->g(), f_color->b(), f_color->a());
((Text *)node)->setTextColor(color);
label->setUnifySizeEnabled(false);
bool IsCustomSize = options->isCustomSize() != 0;
label->ignoreContentAdaptWithSize(!IsCustomSize);
auto widgetOptions = options->widgetOptions();
if (!label->isIgnoreContentAdaptWithSize())
{
Size contentSize(widgetOptions->size()->width(), widgetOptions->size()->height());
//.........这里部分代码省略.........