cocos2d 使用多个单独文件生成动画
- (CCAnimation*) animationWithFile:(NSString*)name frameCount:(int)frameCount delay:(float)delay
{
//动画帧文件集
NSMutableArray* frames = [NSMutableArray arrayWithCapacity:frameCount];
// 文件序号以1开始
for (int i = 1; i <= frameCount; i++)
{
// 生成文件名
NSString* file = [NSString stringWithFormat:@"%@%i.png", name, i];
// 生成图片文件纹理
CCTexture2D* texture = [[CCTextureCache sharedTextureCache] addImage:file];
// 生成动画帧
CGSize texSize = texture.contentSize;
CGRect texRect = CGRectMake(0, 0, texSize.width, texSize.height);
CCSpriteFrame* frame = [CCSpriteFrame frameWithTexture:texture rect:texRect];
// 将当前动画帧添加到集中
[frames addObject:frame];
}
// 将动画集生成动画
return [CCAnimation animationWithFrames:frames delay:delay];
}