原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列]
博客地址:http://blog.csdn.net/qq446569365
一些公司现有项目还是用3.0 Rc2版本进行开发,并未升级到更高版本。一个朋友在开发过程中遇到Label通过setopacity 方法设置透明度时候没有效果的问题。虽然现在很少有人用3.0版本,但是依然发一个博客吧……万一有人遇到了呢。
解决方法很简单:
在Label的createSpriteWithFontDeFinition()函数最后添加一行代码:
_textSprite->updatedisplayedOpacity(_displayedOpacity);
如下:
void Label::createSpriteWithFontDeFinition()
{
_currentLabelType = LabelType::STRING_TEXTURE;
auto texture = new Texture2D;
texture->initWithString(_originalUTF8String.c_str(),_fontDeFinition);
_textSprite = Sprite::createWithTexture(texture);
_textSprite->setAnchorPoint(Point::ANCHOR_BottOM_LEFT);
this->setContentSize(_textSprite->getContentSize());
texture->release();
if (_blendFuncDirty)
{
_textSprite->setBlendFunc(_blendFunc);
}
Node::addChild(_textSprite,Node::INVALID_TAG);
_textSprite->updatedisplayedColor(_displayedColor);
_textSprite->updatedisplayedOpacity(_displayedOpacity); //这行
}<span style="font-size:18px;">
</span>
感谢:http://discuss.cocos2d-x.org/t/cocos2dx-3-0-rc2-label-opacity-not-working-when-not-create--textsprite/13204