Reputation: 16
I'm on the test project of cocos2d-x-v4, I created a node and added a sprite in to it, applying the setOpacity
on the node (0) but it doesn't work, it is working on the sprite but not on the node. I don't understand why it is behaving like this.
This is the code I am trying to apply the opacity on the node:
Node* testNode = Node::create();
testNode->setPosition(100, s.height / 2);
Sprite* testSprite = Sprite::create("cocosui/CloseSelected.png");
testNode->addChild(testSprite);
addChild(testNode);
testNode->setScale(10);
testNode->setOpacity(0);
Upvotes: 0
Views: 43
Reputation: 1
Node* testNode = Node::create();
testNode->setPosition(100, s.height / 2);
// this part is added.
testNode->setCascadeOpacityEnabled(true);
Sprite* testSprite = Sprite::create("cocosui/CloseSelected.png");
testNode->addChild(testSprite); addChild(testNode);
testNode->setScale(10);
testNode->setOpacity(0);
setCascadeOpacityEnabled()
method's default value is false.
This method determines whether its opacity adjustment affects its children or not.
Upvotes: 0