Relation between Node's Visible and Opacity variables

Hi,

Since Cocos2d-x v3, Node::visit doesn’t do anything if the node is invisible (_visible variable), which is a good optimization. But why isn’t _visible automatically set to false when opacity is set to 0?

I am considering fixing this in my own project but I am asking what was the rationale behind this decision. Is there any case where setting the opacity to 0 doesn’t mean that we want the node to be invisible, therefore saving OpenGL draw calls?

I know one example we should keep separate Opacity and Visibility.

When Node A has a child Node B, when A is invisible, the B is also not been rendered.

But if A’s opacity is 0, B 's opacity is greater than 0, we should render B. If opacity 0 equals to invisible, the rendering of Node B is incorrect here.

What your opinion?

Good point owen, but with the new _cascadeOpacityEnabled there is a case where the situation you presented would be incorrect.

If _cascadeOpacityEnabled was enabled, there was no possibility of Node B’s opacity being greater than its parent (Node A) due to this line of the code

_displayedOpacity = _realOpacity * parentOpacity/255.0;

in Node::updateDisplayedOpacity(GLubyte parentOpacity)

therefore Node A should (correctly) be marked as invisible if its opacity was set to 0 since its children would not be drawn for sure.

Yes, you are absolutely right here. But it designed like this, I have no idea whether we should set _visible property to false when the opacity does down to 0.

But I seems a good optimization. Thanks.