带孩子的CCSprite淡出 [英] CCSprite Fadeout with children
问题描述
我正在使用CCSprite
并添加了一些其他CCSprite
对象作为子对象,我正在使用的其他动画(缩放和旋转)效果很好,子对象也获得了动画效果.但是当我使用CCFadeOut
时,它只会淡化父级.
I'm using a CCSprite
with a few other CCSprite
objects added as children, the other animations I'm using (scale and rotate) work great and the children are animated too. But when I'm using CCFadeOut
, it only fades the parent.
我读过淡出不适用于孩子们.除了遍历每个孩子并调用每个孩子的淡入淡出之外,还有其他方法吗?
I've read that fadeout doesn't apply to the children. Is there any way other than iterating over every child and calling the fadeout on each of them?
推荐答案
Gregory Johnson答案使此答案已过时.
嗯,我想您的选择是(从最简单到最复杂的):
Well, I guess your choices are (Ranked from simplest to complex):
1)只需进入cocos2d
库中的CCSprite
类,然后对其进行破解. (< 3开源). (不推荐).
1) Just go into the CCSprite
class in 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)与上述解决方案相同,但子类MyCCSprite
除外,并且从其继承而不是CCSprite
.最后,在新类中覆盖setOpacity:
:
2) Same as the solution above, except subclass CCSprite
to MyCCSprite
, and inherit from 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)对父级和子级进行迭代,对它们运行CCFade
动作. (很傻,如果您问我).
3) Run the CCFade
action on the parent and the children by iterating them. (silly, if you ask me).
重要提示::请记住,opacity
是CCRGBAProtocol
的财产.并非所有CCNode
类都具有它.因此,请确保牢记这一点.
IMPORTANT: Just please, please, please keep in mind that opacity
is a property of the CCRGBAProtocol
. Not all CCNode
classes have it. So, make sure you keep that in mind.
参考文献:
这篇关于带孩子的CCSprite淡出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!