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.
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
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.