在cocos2d 0.9及以下版本中,CCAnimation中可以使用animationWithName,但在1.0及以上版本中,此方法已經不能使用了,而是使用animationWithFrames替代,而 animationWithFrames的參數是一個NSArray類型的資料,是以要經過一些轉換後才能實作,具體實作參照如下例子:
CCTexture2D *texture = [[CCTextureCachesharedTextureCache] addImage:@"***.png"];
CCSpriteFrame *frame = [CCSpriteFrameframeWithTexture:texture rect:CGRectMake(0, 0,texture.contentSize.width,texture.contentSize.height)];
NSArray *array =[[NSArray alloc]initWithObjects:frame, nil];
CCAnimation *animation = [CCAnimationanimationWithFrames:array delay:0.2f];
for(int i = 0; i< 3; i++)
{
int x = i % 3;
[animation addFrameWithTexture:mgr.texturerect:CGRectMake(x*32, 0, 31, 30)];
}
id action = [CCAnimateactionWithAnimation:animation];
[flight runAction:[CCRepeatForeveractionWithAction:action]];
此處的fight是CCSprite類型的變量