我想创建Label&带有自定义字体的cocos2dx 3.0中的MenuItem

时间:2014-08-27 09:18:50

标签: cocos2d-x cocos2d-x-3.0

我想创建菜单项&带标题和标签的标签在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);

但是这段代码有很多警告,我也想为文字设置颜色。

1 个答案:

答案 0 :(得分:1)

不推荐使用

LabelTTFCCMenu,请改为使用LabelMenu类:

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));