Fixed `Label::setGlobalZOrder ` is invalid when label create with system font.

This commit is contained in:
WenhaiLin 2015-08-19 10:22:48 +08:00
parent e3c88533fe
commit 827f05c5e1
2 changed files with 16 additions and 0 deletions

View File

@ -983,6 +983,7 @@ void Label::createSpriteForSystemFont(const FontDefinition& fontDef)
_textSprite = Sprite::createWithTexture(texture); _textSprite = Sprite::createWithTexture(texture);
//set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label
_textSprite->setCameraMask(getCameraMask()); _textSprite->setCameraMask(getCameraMask());
_textSprite->setGlobalZOrder(getGlobalZOrder());
_textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
this->setContentSize(_textSprite->getContentSize()); this->setContentSize(_textSprite->getContentSize());
texture->release(); texture->release();
@ -1027,6 +1028,7 @@ void Label::createShadowSpriteForSystemFont(const FontDefinition& fontDef)
_shadowNode->setBlendFunc(_blendFunc); _shadowNode->setBlendFunc(_blendFunc);
} }
_shadowNode->setCameraMask(getCameraMask()); _shadowNode->setCameraMask(getCameraMask());
_shadowNode->setGlobalZOrder(getGlobalZOrder());
_shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT);
_shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height);
@ -1724,4 +1726,17 @@ FontDefinition Label::_getFontDefinition() const
return systemFontDef; return systemFontDef;
} }
void Label::setGlobalZOrder(float globalZOrder)
{
Node::setGlobalZOrder(globalZOrder);
if (_textSprite)
{
_textSprite->setGlobalZOrder(globalZOrder);
if (_shadowNode)
{
_shadowNode->setGlobalZOrder(globalZOrder);
}
}
}
NS_CC_END NS_CC_END

View File

@ -453,6 +453,7 @@ public:
virtual void removeAllChildrenWithCleanup(bool cleanup) override; virtual void removeAllChildrenWithCleanup(bool cleanup) override;
virtual void removeChild(Node* child, bool cleanup = true) override; virtual void removeChild(Node* child, bool cleanup = true) override;
virtual void setGlobalZOrder(float globalZOrder) override;
CC_DEPRECATED_ATTRIBUTE static Label* create(const std::string& text, const std::string& font, float fontSize, CC_DEPRECATED_ATTRIBUTE static Label* create(const std::string& text, const std::string& font, float fontSize,
const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT, const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,