CCAnimate和CCAnimation有什么不同?

use*_*842 1 iphone cocos2d-iphone ios

我用cocos2d创建了一个新项目,然后创建了一个图层和一个精灵.我正在尝试将动画应用到我的精灵中,我发现了一些关于它的示例.但我不明白之间的差别CCAnimationCCAnimate,所以我还没有应用任何动画,我还没有精灵.

这两者有什么区别,它们的真正含义是什么?怎么用?

任何人都可以解释一下吗?请帮我.

Hai*_*lei 5

以下是cocos2d-iphone编程指南中的"使用Sprites和Sprite批处理节点"中的代码:

......

NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 15; i++) {
    CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"grossini_dance_%02d.png",i]];
    [animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithName:@"dance" delay:0.2f frames:animFrames];
[sprite runAction:[CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]]];
Run Code Online (Sandbox Code Playgroud)

如您所见,您需要使用两者CCAnimateCCAnimation在sprite上运行基于CCSpriteFrame的动画.每个描述CCAnimation:

CCAnimation对象包含CCSpriteFrame对象,以及帧之间可能的延迟.您可以CCAnimation使用该CCAnimate操作为对象设置动画.例:

[sprite runAction:[CCAnimate actionWithAnimation:animation]]; 
Run Code Online (Sandbox Code Playgroud)

一般来说,CCAnimation是框架容器的包装.CCAnimate精灵需要做的动作 - 实际上它是一个子类CCAction,它表示精灵可以"运行"的动作,例如移动,跳跃,旋转等.你可以使用它的其他子类来做某些事情您的精灵上的动画,而不是自己创建框架.有像一试CCFadeIn,CCRotateBy等等.