缓存CCAnimation

时间:2012-09-11 10:11:16

标签: animation cocos2d-iphone

在Cocos2D中缓存CCAnimations是否有一些最佳实践?目前,我基本上每次出现在屏幕上时都会重新计算精灵的“出现”动画。以某种方式在实例类中缓存动画不是明智的吗?

目前,对于某些游戏条件,我会运行此代码数千次:

CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
[frameCache addSpriteFramesWithFile:@"WichserAnimations.plist"];

NSMutableArray* frames = [NSMutableArray arrayWithCapacity:8];
for (int i = 41; i <= 48; i++) {
    NSString* file = [NSString stringWithFormat:@"intro_prep__Main_000%i.png", i];
    CCSpriteFrame* frame = [frameCache spriteFrameByName:file];
    [frames addObject:frame];
}

CCAnimation* anim    = [CCAnimation animationWithSpriteFrames:frames delay:0.05f];
CCAnimate*   connect = [CCAnimate actionWithAnimation:anim];        
[self runAction:connect];

我想把“连接”CCAnimate对象放到sprite中以供以后重复使用,但这似乎不起作用:(任何建议都将受到高度赞赏

1 个答案:

答案 0 :(得分:1)

动画缓存类名为CCAnimationCache