diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index d1a033b578..70459f3497 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -702,6 +702,7 @@ void Label::alignText() auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index)); if (batchNode) { + _isOpacityModifyRGB = batchNode->getTexture()->hasPremultipliedAlpha(); _blendFunc = batchNode->getBlendFunc(); batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); batchNode->setPosition(Vec2::ZERO); diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp index 5c564a1f99..5590a1086a 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.cpp @@ -38,6 +38,7 @@ NewLabelTests::NewLabelTests() ADD_TEST_CASE(LabelFNTPadding); ADD_TEST_CASE(LabelFNTOffset); ADD_TEST_CASE(LabelFNTColor); + ADD_TEST_CASE(LabelFNTOpacity); ADD_TEST_CASE(LabelFNTHundredLabels); ADD_TEST_CASE(LabelFNTMultiLine); ADD_TEST_CASE(LabelFNTandTTFEmpty); @@ -331,6 +332,31 @@ std::string LabelFNTColor::subtitle() const return "Testing color"; } +LabelFNTOpacity::LabelFNTOpacity() +{ + auto s = Director::getInstance()->getWinSize(); + + auto label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Opacity 100"); + label->setOpacity(100); + addChild(label); + label->setPosition(Vec2(s.width / 2, s.height / 2)); + + label = Label::createWithBMFont("fonts/bitmapFontTest5.fnt", "Opacity 200"); + label->setOpacity(200); + addChild(label); + label->setPosition(Vec2(s.width / 2, s.height / 3)); +} + +std::string LabelFNTOpacity::title() const +{ + return "New Label + .FNT file"; +} + +std::string LabelFNTOpacity::subtitle() const +{ + return "Testing opacity"; +} + LabelFNTHundredLabels::LabelFNTHundredLabels() { // Upper Label diff --git a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h index 2b8cbc77a2..e92e7e062d 100644 --- a/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h +++ b/tests/cpp-tests/Classes/LabelTest/LabelTestNew.h @@ -80,6 +80,17 @@ public: virtual std::string subtitle() const override; }; +class LabelFNTOpacity : public AtlasDemoNew +{ +public: + CREATE_FUNC(LabelFNTOpacity); + + LabelFNTOpacity(); + virtual std::string title() const override; + + virtual std::string subtitle() const override; +}; + class LabelFNTHundredLabels : public AtlasDemoNew { public: