Reputation: 101
I found out that the setopacity function does not work for one of our cocos2d games, it is using cocos2d 1.0.1. Not matter what value I set, the opacity of all ccnodes are always 255, and the fadein/fadeout actions are not working either. We have another game which is using the same version of cocos2d but that one works perfectly. Does anyone have any clue about how to solve this problem?
Upvotes: 1
Views: 2476
Reputation: 1
tween(this.node.getChildByName("Black_Screen").getComponent(UIOpacity)).to(0.2, { opacity: 255 }).start(); Add Uiopacity in node
Upvotes: 0
Reputation: 531
Basic DrawNode can't handle opacity by itself either (this feature is in the plan for cocos2d-4.*).
You can inherite your class from Node
or DrawNode
and implement setOpacity
like this:
void AlphaNode::setOpacity(GLubyte opac) {
mOpacity = opac;
if (_bufferCount) {
for (int i = 0; i < _bufferCount; i++) {
_buffer[i].colors.a = mOpacity;
}
}
if (_bufferCountGLPoint) {
for (int i = 0; i < _bufferCountGLPoint; i++) {
_bufferGLPoint[i].colors.a = mOpacity;
}
}
if (_bufferCountGLLine) {
for (int i = 0; i < _bufferCountGLLine; i++) {
_bufferGLLine[i].colors.a = mOpacity;
}
_dirtyGLLine = true;
}
_dirty = true;
}
I think you can do something like this for Node
.
Upvotes: 0
Reputation: 19251
CCNodes don't actually have a texture (image), so there is no opacity property for them. I am assuming you think that setting the opacity of a CCNode will affect its children, which it would not. opacity only affects the texture of the object that you are setting the opacity for. You can set the opacity of a CCSprite, because it has a texture, but doing so would not affect that CCSprite's children. You would have to loop through all of the children, and set the opacity for each if you wanted to affect the opacity of more than one CCSprite.
Upvotes: 2