diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index 301744cc32..05cd51f759 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -1441,7 +1441,8 @@ void Node::setOpacity(GLubyte opacity) void Node::updateDisplayedOpacity(GLubyte parentOpacity) { _displayedOpacity = _realOpacity * parentOpacity/255.0; - + updateColor(); + if (_cascadeOpacityEnabled) { _children.forEach([this](Node* child){ @@ -1457,7 +1458,7 @@ bool Node::isCascadeOpacityEnabled(void) const void Node::setCascadeOpacityEnabled(bool cascadeOpacityEnabled) { - if (_cascadeColorEnabled == cascadeOpacityEnabled) + if (_cascadeOpacityEnabled == cascadeOpacityEnabled) { return; } @@ -1491,7 +1492,7 @@ void Node::disableCascadeOpacity() _displayedOpacity = _realOpacity; _children.forEach([this](Node* child){ - child->disableCascadeOpacity(); + child->updateDisplayedOpacity(255); }); } @@ -1517,6 +1518,7 @@ void Node::updateDisplayedColor(const Color3B& parentColor) _displayedColor.r = _realColor.r * parentColor.r/255.0; _displayedColor.g = _realColor.g * parentColor.g/255.0; _displayedColor.b = _realColor.b * parentColor.b/255.0; + updateColor(); if (_cascadeColorEnabled) { @@ -1564,7 +1566,7 @@ void Node::updateCascadeColor() void Node::disableCascadeColor() { _children.forEach([this](Node* child){ - child->disableCascadeColor(); + child->updateDisplayedColor(Color3B::WHITE); }); } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index ff6f65af52..3363deec46 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1428,6 +1428,7 @@ protected: virtual void disableCascadeOpacity(); virtual void updateCascadeColor(); virtual void disableCascadeColor(); + virtual void updateColor() {} float _rotationX; ///< rotation angle on x-axis @@ -1501,11 +1502,11 @@ protected: #endif // opacity controls - GLubyte _displayedOpacity; + GLubyte _displayedOpacity; GLubyte _realOpacity; - Color3B _displayedColor; + Color3B _displayedColor; Color3B _realColor; - bool _cascadeColorEnabled; + bool _cascadeColorEnabled; bool _cascadeOpacityEnabled; private: diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp index d85e3aed13..c395be1adf 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.cpp @@ -22,7 +22,9 @@ static std::function createFunctions[] = { CL(LayerIgnoreAnchorPointPos), CL(LayerIgnoreAnchorPointRot), CL(LayerIgnoreAnchorPointScale), - CL(LayerExtendedBlendOpacityTest) + CL(LayerExtendedBlendOpacityTest), + CL(LayerBug3162A), + CL(LayerBug3162B), }; static int sceneIdx=-1; @@ -863,3 +865,91 @@ string LayerExtendedBlendOpacityTest::subtitle() return "You should see 3 layers"; } +// LayerBug3162A +void LayerBug3162A::onEnter() +{ + LayerTest::onEnter(); + + Size size = VisibleRect::getVisibleRect().size; + size.width = size.width / 2; + size.height = size.height / 3; + Color4B color[3] = {Color4B(255, 0, 0, 255), Color4B(0, 255, 0, 255), Color4B(0, 0, 255, 255)}; + + for (int i = 0; i < 3; ++i) + { + _layer[i] = LayerColor::create(color[i]); + _layer[i]->setContentSize(size); + _layer[i]->setPosition(Point(size.width/2, size.height/2) - Point(20, 20)); + _layer[i]->setOpacity(150); + _layer[i]->setCascadeOpacityEnabled(true); + if (i > 0) + { + _layer[i-1]->addChild(_layer[i]); + } + } + + this->addChild(_layer[0]); + + schedule(schedule_selector(LayerBug3162A::step), 0.5, kRepeatForever, 0); +} + +void LayerBug3162A::step(float dt) +{ + _layer[0]->setCascadeOpacityEnabled(!_layer[0]->isCascadeOpacityEnabled()); +} + +std::string LayerBug3162A::title() +{ + return "Bug 3162 red layer cascade opacity eable/disable"; +} + +std::string LayerBug3162A::subtitle() +{ + return "g and b layer opacity is effected/diseffected with r layer"; +} + +// LayerBug3162B +void LayerBug3162B::onEnter() +{ + LayerTest::onEnter(); + + Size size = VisibleRect::getVisibleRect().size; + size.width = size.width / 2; + size.height = size.height / 3; + Color4B color[3] = {Color4B(200, 0, 0, 255), Color4B(150, 0, 0, 255), Color4B(100, 0, 0, 255)}; + + for (int i = 0; i < 3; ++i) + { + _layer[i] = LayerColor::create(color[i]); + _layer[i]->setContentSize(size); + _layer[i]->setPosition(Point(size.width/2, size.height/2) - Point(20, 20)); + //_layer[i]->setOpacity(150); + if (i > 0) + { + _layer[i-1]->addChild(_layer[i]); + } + } + + this->addChild(_layer[0]); + + _layer[0]->setCascadeColorEnabled(true); + _layer[1]->setCascadeColorEnabled(true); + _layer[2]->setCascadeColorEnabled(true); + + schedule(schedule_selector(LayerBug3162B::step), 0.5, kRepeatForever, 0); +} + +void LayerBug3162B::step(float dt) +{ + _layer[0]->setCascadeColorEnabled(!_layer[0]->isCascadeColorEnabled()); +} + +std::string LayerBug3162B::title() +{ + return "Bug 3162 bottom layer cascade opacity eable/disable"; +} + +std::string LayerBug3162B::subtitle() +{ + return "u and m layer opacity is effected/diseffected with b layer"; +} diff --git a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h index f54173cea5..58510abab2 100644 --- a/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h +++ b/samples/Cpp/TestCpp/Classes/LayerTest/LayerTest.h @@ -174,6 +174,34 @@ public: virtual std::string subtitle(); }; +class LayerBug3162A : public LayerTest +{ +public: + CREATE_FUNC(LayerBug3162A); + virtual void onEnter(); + virtual std::string title(); + virtual std::string subtitle(); + + void step(float dt); + +private: + LayerColor* _layer[3]; +}; + +class LayerBug3162B : public LayerTest +{ +public: + CREATE_FUNC(LayerBug3162B); + virtual void onEnter(); + virtual std::string title(); + virtual std::string subtitle(); + + void step(float dt); + +private: + LayerColor* _layer[3]; +}; + class LayerTestScene : public TestScene { public: