[寒江孤叶丶的Cocos2d-x之旅_19]Cocos2d-x 3.0 rc2 版本 Label 的setOpacity 函数失效,无法设置透明度问题的解决办法

前端之家收集整理的这篇文章主要介绍了[寒江孤叶丶的Cocos2d-x之旅_19]Cocos2d-x 3.0 rc2 版本 Label 的setOpacity 函数失效,无法设置透明度问题的解决办法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

原创文章,欢迎转载,转载请注明:文章来自[寒江孤叶丶的Cocos2d-x之旅系列]

博客地址:http://blog.csdn.net/qq446569365

@H_404_4@ 一些公司现有项目还是用3.0 Rc2版本进行开发,并未升级到更高版本。一个朋友在开发过程中遇到Label通过setOpacity 方法设置透明度时候没有效果的问题。虽然现在很少有人用3.0版本,但是依然发一个博客吧……万一有人遇到了呢。

@H_404_4@ 解决方法很简单:

在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 原文链接:https://www.f2er.com/cocos2dx/345664.html

猜你在找的Cocos2d-x相关文章