From 827f05c5e1abc3d7fb3cf67f7621ddc83925049b Mon Sep 17 00:00:00 2001 From: WenhaiLin Date: Wed, 19 Aug 2015 10:22:48 +0800 Subject: [PATCH] Fixed `Label::setGlobalZOrder ` is invalid when label create with system font. --- cocos/2d/CCLabel.cpp | 15 +++++++++++++++ cocos/2d/CCLabel.h | 1 + 2 files changed, 16 insertions(+) diff --git a/cocos/2d/CCLabel.cpp b/cocos/2d/CCLabel.cpp index a8643b3640..64a716cd3e 100644 --- a/cocos/2d/CCLabel.cpp +++ b/cocos/2d/CCLabel.cpp @@ -983,6 +983,7 @@ void Label::createSpriteForSystemFont(const FontDefinition& fontDef) _textSprite = Sprite::createWithTexture(texture); //set camera mask using label's camera mask, because _textSprite may be null when setting camera mask to label _textSprite->setCameraMask(getCameraMask()); + _textSprite->setGlobalZOrder(getGlobalZOrder()); _textSprite->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); this->setContentSize(_textSprite->getContentSize()); texture->release(); @@ -1027,6 +1028,7 @@ void Label::createShadowSpriteForSystemFont(const FontDefinition& fontDef) _shadowNode->setBlendFunc(_blendFunc); } _shadowNode->setCameraMask(getCameraMask()); + _shadowNode->setGlobalZOrder(getGlobalZOrder()); _shadowNode->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); _shadowNode->setPosition(_shadowOffset.width, _shadowOffset.height); @@ -1724,4 +1726,17 @@ FontDefinition Label::_getFontDefinition() const return systemFontDef; } +void Label::setGlobalZOrder(float globalZOrder) +{ + Node::setGlobalZOrder(globalZOrder); + if (_textSprite) + { + _textSprite->setGlobalZOrder(globalZOrder); + if (_shadowNode) + { + _shadowNode->setGlobalZOrder(globalZOrder); + } + } +} + NS_CC_END diff --git a/cocos/2d/CCLabel.h b/cocos/2d/CCLabel.h index 931e0f577d..96a0c99cf8 100644 --- a/cocos/2d/CCLabel.h +++ b/cocos/2d/CCLabel.h @@ -453,6 +453,7 @@ public: virtual void removeAllChildrenWithCleanup(bool cleanup) 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, const Size& dimensions = Size::ZERO, TextHAlignment hAlignment = TextHAlignment::LEFT,