Closed HassamChaudhary1 closed 11 months ago
Your code is missing a call to setCascadeOpacityEnabled()
. The cascading of the opacity value is false by default, so add this line to check if it fixes your issue:
testNode->setCascadeOpacityEnabled(true);
It is also not working on the Axmol demo project
What demo project? If you meant cpp-tests
, then specifically which test are you referring to?
This will work for newly created node but it will not work for a full project. I checked on cocos-2dx (previous) and their Cascading is off and opacity is working there without adding any additional code.
I can't use setCascadeOpacityEnabled on my project bcoz I updated my project and previously it was working Fine and now why I need to do setCascadeOpacityEnabled?
Yes cpp-tests. I added my own node to check bcoz All the tests are using setOpacity on Sprite or other component but not using directly on the node.
Is there any way to not adding any additional line like
testNode->setCascadeOpacityEnabled(true);
For more Info: If I set Opacity in Cocos2d-x editor of any node it also not reflect on the game.
Yes cpp-tests. I added my own node to check bcoz All the tests are using setOpacity on Sprite or other component but not using directly on the node.
Any modification to the cpp-tests project should always be mentioned, since stating that the test project didn't work without any context confuses things.
Regardless of that, just because something works a certain way in Cocos2d-x doesn't mean that it was working correctly. You can check what has changed between Cocos2d-x v4 to Axmol to figure out why it, apparently, has different behavior.
I got the point, I am going through all the places to find out the solution or reason of "Why we need to enable the cascading to use opacity on node?" If we need to set the cascading to enabled then why it's default value is false, why shouldn't we set it's value to true by default?
Regardless of that, just because something works a certain way in Cocos2d-x doesn't mean that it was working correctly. You can check what has changed between Cocos2d-x v4 to Axmol to figure out why it, apparently, has different behavior.
I compared the both codes, code is similar, I'm confused when I use opacity on editor and then run my code with the updated .csb file, it also not shown opacity on the phone but when I call node->getDisplayedOpacity() it returns 0. On game UI, it's opacity seems 255.
I'm confused when I use opacity on editor
What editor are you referring to? If it's Cocos Studio, then that editor hasn't been supported for many years by the Cocos team, and the code related to it is, technically, deprecated. I'm actually surprised the code to support it is still included in Axmol, but you'll have to go through that code and check if something has changed, or if there is some bug in there that is affecting your project.
Yes It's Cocos Studio. So, As far as I understand, to use the opacity on node, we have to use setCascadeOpacityEnabled(true);
, right?
Yes It's Cocos Studio. So, As far as I understand, to use the opacity on node, we have to use
setCascadeOpacityEnabled(true);
, right?
The opacity of a specific node is set by setOpacity()
, but, if you need that opacity to cascade to child nodes of that node, then yes, you need to call setCascadeOpacityEnabled(true);
on that parent. That goes for any node that has child nodes, so if you have a tree of nodes, then you need to make sure all nodes with child nodes also have cascade opacity set to true
.
Refer to the discussion thread, this post, for a work-around. Please close this issue, since it's not a bug in Axmol.
converted to discuss
NOTE: Opacity is working on the sprite. Issue is with the Node. It is also not working on the Axmol demo project
Test Code: