Merge pull request #12914 from WenhaiLin/v3.8-label-bmfont-opacity

Label:Fixed opacity setting is invalid with bitmap font.
This commit is contained in:
pandamicro 2015-07-20 18:02:49 +08:00
commit 641ff2abf4
3 changed files with 38 additions and 0 deletions

View File

@ -702,6 +702,7 @@ void Label::alignText()
auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index)); auto batchNode = SpriteBatchNode::createWithTexture(textures.at(index));
if (batchNode) if (batchNode)
{ {
_isOpacityModifyRGB = batchNode->getTexture()->hasPremultipliedAlpha();
_blendFunc = batchNode->getBlendFunc(); _blendFunc = batchNode->getBlendFunc();
batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT); batchNode->setAnchorPoint(Vec2::ANCHOR_TOP_LEFT);
batchNode->setPosition(Vec2::ZERO); batchNode->setPosition(Vec2::ZERO);

View File

@ -38,6 +38,7 @@ NewLabelTests::NewLabelTests()
ADD_TEST_CASE(LabelFNTPadding); ADD_TEST_CASE(LabelFNTPadding);
ADD_TEST_CASE(LabelFNTOffset); ADD_TEST_CASE(LabelFNTOffset);
ADD_TEST_CASE(LabelFNTColor); ADD_TEST_CASE(LabelFNTColor);
ADD_TEST_CASE(LabelFNTOpacity);
ADD_TEST_CASE(LabelFNTHundredLabels); ADD_TEST_CASE(LabelFNTHundredLabels);
ADD_TEST_CASE(LabelFNTMultiLine); ADD_TEST_CASE(LabelFNTMultiLine);
ADD_TEST_CASE(LabelFNTandTTFEmpty); ADD_TEST_CASE(LabelFNTandTTFEmpty);
@ -331,6 +332,31 @@ std::string LabelFNTColor::subtitle() const
return "Testing color"; 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() LabelFNTHundredLabels::LabelFNTHundredLabels()
{ {
// Upper Label // Upper Label

View File

@ -80,6 +80,17 @@ public:
virtual std::string subtitle() const override; 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 class LabelFNTHundredLabels : public AtlasDemoNew
{ {
public: public: