【问题标题】:put sprites hidden on screen,than fade them in将精灵隐藏在屏幕上,而不是将它们淡入
【发布时间】:2013-01-31 09:44:11
【问题描述】:

我需要在屏幕上添加一些CCsprites,以便稍后淡入屏幕。 我无法隐藏它们,因为 CCFade 操作不适用于隐藏的精灵或带有 opacity=0 的精灵。

我所做的是将它们放在屏幕上并淡出它们:

[colors[i] runAction:[CCFadeOut actionWithDuration:0]];
[self addChild:colors[i] z:0];

原来在零时间淡出是not unseen,所以当我将它们添加到CCScene. 时,它们会出现一秒钟

我如何将它们放在屏幕上不被看到,而不是使用CCFadeIn 操作淡入它们?

【问题讨论】:

    标签: cocos2d-iphone


    【解决方案1】:

    您可以使用序列来堆叠操作。请参阅我的一个项目中的以下示例:

    CCSprite *frame1 = [CCSprite spriteWithSpriteFrame:[frames objectAtIndex:0]];
    frame1.flipX = self.flipX;
    frame1.scale = self.scaling;
    frame1.visible = NO;
    frame1.opacity = 255;
    frame1.rotation = self.rotation;
    frame1.position = self.offset;
    animation = [CCAnimation animationWithSpriteFrames:frames delay:(duration / self.numberOfFrames)];
    id stall = [CCDelayTime actionWithDuration:delay];
    id show = [CCShow action];
    id animate = [CCAnimate actionWithAnimation:animation];
    id hide = [CCHide action];
    id clean = [CCCallBlock actionWithBlock:^{
        [frame1 removeFromParentAndCleanup:YES];
    
    }];
    id enchiladas = [CCSequence actions:stall, show, animate, hide, clean, nil];
    
    [node addChild:frame1 z:5];
    [frame1 runAction:enchiladas];
    

    类似的事情。我想运行一个动画,它会在设定的延迟时间后出现,然后在完成后自行消失并清理。

    【讨论】:

      【解决方案2】:

      你可以使用 sprite.opacity =0;最初 并且在动作中你可以增加不透明度

      【讨论】:

      • 使用 [CCFadeTo actionWithDuration:1.25f opacity:255] 在 1.25 秒内从当前不透明度淡化到完全不透明度(例如)。
      猜你喜欢
      • 2013-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-24
      相关资源
      最近更新 更多