我正在制作消息窗口。我想控制每个字母。
我运行 Sprite#setVisible 来控制每个字母,但它不起作用。
Label#setVisible 正常工作。
这是我的代码。
void MessageWindowLayer::setText(std::string& text) {
this->message = text;
Label* msgLabel = Label::createWithTTF(message, "fonts/JKG-L_3.ttf", 24);
msgLabel->setPosition(cocos2d::ccp(0, back->getContentSize().height));
msgLabel->setAnchorPoint(ccp(0, 1));
this->runAction(CallFunc::create([msgLabel]() {
int num = msgLabel->getStringLength() + msgLabel->getStringNumLines() - 1;
for (int i = 0; i < num; i++) {
Sprite* letter = msgLabel->getLetter(i);
if (nullptr != letter) {
letter->setVisible(false);
log("isVisible:%d", letter->isVisible()); // isVisible returns "0" but letters still show
//letter->runAction(
// Sequence::create(
// DelayTime::create(0.2f*i),
// //JumpBy::create(0.5f, Point::ZERO, 60, 1),
// Show::create(),
// NULL
// ));
}
}
}));
parentLayer->addChild(msgLabel);
}
谢谢。
编辑: 我将 cocos 版本“3.8 final”更改为“3.7.1”,它开始工作了。 所以我在 github 上打开了问题。
最佳答案
ttfLabel 不支持 'getLetter()' 如果你想控制每个字母,你需要使用 bmfontLabel
关于c++ - Cocos2d-x setVisible 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32571476/