Merge pull request #14661 from zilongshanren/v3.10

fix scale9sprite global zorder issue.
This commit is contained in:
zilongshanren 2015-12-14 13:56:29 +08:00
commit 6781c96fe0
4 changed files with 121 additions and 2 deletions

View File

@ -670,7 +670,7 @@ namespace ui {
void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
if (_scale9Image) {
if (_scale9Image && _scale9Enabled) {
#if CC_USE_CULLING
// Don't do calculate the culling if the transform was not updated
auto visitingCamera = Camera::getVisitingCamera();
@ -758,11 +758,20 @@ namespace ui {
break;
}
if (!_scale9Enabled && _scale9Image && _scale9Image->getLocalZOrder() < 0 )
{
_scale9Image->visit(renderer, _modelViewTransform, flags);
}
// draw self
//
if (isVisitableByVisitingCamera())
this->draw(renderer, _modelViewTransform, flags);
if (!_scale9Enabled && _scale9Image && _scale9Image->getLocalZOrder() >= 0 )
{
_scale9Image->visit(renderer, _modelViewTransform, flags);
}
for(auto it=_children.cbegin()+i; it != _children.cend(); ++it)
(*it)->visit(renderer, _modelViewTransform, flags);
@ -1337,4 +1346,13 @@ namespace ui {
CC_SAFE_RELEASE_NULL(this->_scale9Image);
}
void Scale9Sprite::setGlobalZOrder(float globalZOrder)
{
Node::setGlobalZOrder(globalZOrder);
if (_scale9Image)
{
_scale9Image->setGlobalZOrder(globalZOrder);
}
}
}}

View File

@ -577,6 +577,8 @@ namespace ui {
/**
* @brief Toggle 9-slice feature.
* If Scale9Sprite is 9-slice disabled, the Scale9Sprite will rendered as a normal sprite.
* @warning: Don't use setScale9Enabled(false), use setRenderingType(RenderingType::SIMPLE) instead.
* The setScale9Enabled(false) is kept only for back back compatibility.
* @param enabled True to enable 9-slice, false otherwise.
* @js NA
*/
@ -657,6 +659,7 @@ namespace ui {
virtual float getScale() const override;
using Node::getScaleZ;
virtual void setCameraMask(unsigned short mask, bool applyChildren = true) override;
virtual void setGlobalZOrder(float globalZOrder) override;
/**
* Set the slice sprite rendering type.

View File

@ -55,6 +55,8 @@ UIScale9SpriteTests::UIScale9SpriteTests()
ADD_TEST_CASE(UIS9NinePatchTest);
ADD_TEST_CASE(UIS9BatchTest);
ADD_TEST_CASE(UIS9ToggleRenderingTypeTest);
ADD_TEST_CASE(UIS9GlobalZOrderTest);
ADD_TEST_CASE(UIS9EnableScale9FalseTest);
}
// UIScale9SpriteTest
@ -92,6 +94,7 @@ bool UIScale9SpriteTest::init()
normalSprite2->setPosition(120, 270);
normalSprite2->setScale9Enabled(false);
normalSprite2->setOpacity(100);
normalSprite2->setContentSize(normalSprite2->getContentSize() * 2);
this->addChild(normalSprite2);
normalSprite2->setColor(Color3B::GREEN);
normalSprite2->runAction(action);
@ -994,3 +997,82 @@ bool UIS9ToggleRenderingTypeTest::init()
return false;
}
bool UIS9GlobalZOrderTest::init()
{
if (UIScene::init()) {
auto winSize = Director::getInstance()->getWinSize();
float x = winSize.width / 2;
float y = 0 + (winSize.height / 2 - 20);
auto label = Label::createWithSystemFont("The green scale9sprite is in the back.", "Arial", 15);
label->setPosition(Vec2(winSize.width/2, winSize.height - 60));
this->addChild(label);
auto blocks = ui::Scale9Sprite::create("Images/blocks9.png");
blocks->setPosition(Vec2(x, y));
blocks->setPreferredSize(Size(96*2, 96*1.5));
blocks->setColor(Color3B::RED);
blocks->setGlobalZOrder(1);
this->addChild(blocks);
auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png");
blocks2->setPosition(Vec2(x, y));
blocks2->setPreferredSize(Size(96*3, 96));
blocks2->setGlobalZOrder(0);
blocks2->setColor(Color3B::GREEN);
this->addChild(blocks2);
return true;
}
return false;
}
bool UIS9EnableScale9FalseTest::init()
{
if (UIScene::init()) {
auto winSize = Director::getInstance()->getWinSize();
float x = winSize.width / 2 + 50;
float y = 0 + (winSize.height / 2 + 10);
auto label = Label::createWithSystemFont("Only the yellow block intersect with the green one.", "Arial", 15);
label->setPosition(Vec2(winSize.width/2, winSize.height - 60));
this->addChild(label);
auto blocks = ui::Scale9Sprite::create("Images/blocks9.png");
blocks->setScale9Enabled(false);
blocks->setPosition(Vec2(x, y));
blocks->setPreferredSize(Size(96*2, 96));
blocks->setColor(Color3B::RED);
blocks->setGlobalZOrder(1);
this->addChild(blocks);
auto blocks2 = ui::Scale9Sprite::create("Images/blocks9.png");
blocks2->setScale9Enabled(false);
blocks2->setPosition(Vec2(0, 0));
blocks2->setPreferredSize(Size(96*1.5, 96));
blocks2->setGlobalZOrder(0);
blocks2->setColor(Color3B::GREEN);
blocks->addChild(blocks2);
auto blocks3 = ui::Scale9Sprite::create("Images/blocks9.png");
blocks3->setScale9Enabled(false);
blocks3->setPosition(Vec2(0, 0));
blocks3->setPreferredSize(Size(96, 96));
blocks3->setGlobalZOrder(2);
blocks3->setColor(Color3B::YELLOW);
blocks2->addChild(blocks3);
return true;
}
return false;
}

View File

@ -274,4 +274,20 @@ public:
virtual bool init() override;
};
class UIS9GlobalZOrderTest: public UIScene
{
public:
CREATE_FUNC(UIS9GlobalZOrderTest);
virtual bool init() override;
};
class UIS9EnableScale9FalseTest: public UIScene
{
public:
CREATE_FUNC(UIS9EnableScale9FalseTest);
virtual bool init() override;
};
#endif /* defined(__cocos2d_tests__UIScale9SpriteTest__) */