我想创建菜单项&带标题和标签的标签在cocos2dx 3.0中为其标题添加颜色
对于标签m使用
LabelTTF *designInfoLabel;
if(temp == 1){
designInfoLabel = LabelTTF::create("App", "Helvetica", 15, Size(545, 32), TextHAlignment::CENTER);
}
else{
designInfoLabel = LabelTTF::create("App", "Helvetica", 13, Size(545, 32), TextHAlignment::CENTER);
}
designInfoLabel->setPosition(100,100));
this->addChild(designInfoLabel);
但是这段代码有很多警告,我也想为文字设置颜色。
答案 0 :(得分:1)
LabelTTF
和CCMenu
,请改为使用Label
和Menu
类:
Label *designInfoLabel;
if(temp == 1){
designInfoLabel = Label::createWithTTF("App", "Helvetica.ttf", 15, Size(545, 32), TextHAlignment::CENTER);
}
else{
designInfoLabel = Label::createWithTTF("App", "Helvetica.ttf", 13, Size(545, 32), TextHAlignment::CENTER);
}
designInfoLabel->setPosition(100,100));
this->addChild(designInfoLabel);
Menu *buttonsMenu = Menu::create(supportMenuItem, nullptr);
buttonsMenu->setPosition(Vec2(0.0, 0.0));
this->addChild(buttonsMenu, 1);
要设置标签的颜色,您可以调用Label::setTextColor(const Color4B &color);
功能。例如:
designInfoLabel->setTextColor(Color4B::BLACK);
或直接设置RGBA:
designInfoLabel->setTextColor(Color4B(0, 0, 0, 0));