【问题标题】:CCSprite frame number during animationCCSprite 动画时的帧数
【发布时间】:2012-11-17 18:53:17
【问题描述】:

我有一个 CCSpriteSheet 和一个 CCSpriteBatchNode 动画,从 .png 和 .plist 文件完美运行,但是,有没有办法知道动画在哪个帧中以便启动另一个 CCAction??

例如,我有一个 30 帧的 CCAnimation,我想在动画位于第 15 帧时为另一个精灵设置动画。这可能吗??

提前致谢。

【问题讨论】:

  • 不知道。但是在您的示例中,您可以通过安排一个方法来做到这一点。基本上,如果你的动画每帧有 0.05 的延迟,那么你应该安排一个方法在 (0.05 * 15) 之后触发。此类方法执行其他动画。

标签: cocos2d-iphone


【解决方案1】:

将动画分割成多个部分并使用 CCSequence。例如:

CCAction *Action = [CCSequence actions:
                        [CCAnimate actionWithAnimation:myCCanimationPart1],
                        [CCCallBlock actionWithBlock:^
                         {
                            [myOtherSprite runAction:(otherAnimationAction)];
                         }],
                        [CCAnimate actionWithAnimation:myCCanimationPart2],
                        nil];

【讨论】:

  • 这是我最初的方法,也是我最后向客户提出的解决方案。
【解决方案2】:

我通常用我的一个游戏中的这个代码片段来满足这种需求:

float stall;
CCAnimation *secondAnim;
CCSprite *secondSprite;
NSString *dyingFx;
id sound = (self.alive ? [GENoopAction action] : 
                         [GEPlayFx actionWithSoundFile:dyingFx]
            );

id second = [CCSequence actions:
        [CCDelayTime actionWithDuration:stall]
        , [CCShow action]
        , sound
        , [CCAnimate actionWithAnimation:secondAnim]
        , [CCCallFunc actionWithTarget:self selector:@selector(hurtComplete)]
];
secondSprite.visible= NO;
[secondSprite runAction:second];

GEPlayFx 和 GENoopAction 是我为自己创建的玩具(CCActionInstant 实现)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多