CCSprite Fadeout with kids

I use CCSprite with several other CCSprite objects added as children, the other animations that I use (zoom and rotate) work fine, and the children also animate. But when I use CCFadeOut , it only fades away the parent.

I read that fadeout does not apply to children. Is there any other way besides iterating over each child and causing attenuation on each of them?

+4
source share
2 answers

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:

+7
source

Like from Cocos2d ver. 2.1, CCNodeRGBA has the BOOL property "CascadeOpacity". Set it to YES on the parent CCSprite to weaken the child nodes as well as the parent.

+9
source

Source: https://habr.com/ru/post/1434025/


All Articles