This answer is deprecated. Gregory Johnson's answer.
Well, I think your choice (from simple to complex):
1) Just go into the CCSprite class in the cocos2d library and hack it. (<3 open source). ( not recommended ).
-(void) setOpacity:(GLubyte) anOpacity { opacity_ = anOpacity; // special opacity for premultiplied textures if( opacityModifyRGB_ ) [self setColor: colorUnmodified_]; [self updateColor]; for (id<CCRGBAProtocol> child in children ) { // You should check if child responds to selector or conforms to CCRGBAProtocol. [child setOpacity:opacity]; } }
2) The same as above, except for the subclass CCSprite before MyCCSprite , and inherits it instead of CCSprite . Finally, override setOpacity: in the new class:
- (void) setOpacity:(GLubyte)opacity { [super setOpacity:opacity]; for(id<CCRGBAProtocol> child in children) { [child setOpacity:opacity]; } }
3) Run the CCFade action for parents and children, iterating them. (stupid if you ask me).
IMPORTANT: Just please, please keep in mind that opacity is a property of CCRGBAProtocol . Not all CCNode classes have it. So make sure you remember that.
Literature:
source share