試試這個代碼
CCSprite *sprite = [CCSprite spriteWithImageNamed:@"sv_anim_1.png"]; // comes from your .plist file
sprite.position = ccp([[CCDirector sharedDirector] viewSize].width/2, [[CCDirector sharedDirector] viewSize].height/2);
CCSpriteBatchNode *batchNode = [CCSpriteBatchNode batchNodeWithFile:@"scene1atlas.png"];
[batchNode addChild:sprite];
[self addChild:batchNode];
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 5; i++)
{
//NSString *str=[NSString stringWithFormat:@"an1_anim%d.png",i];
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"an1_anim%d.png",i]];
[animFrames addObject:frame];
}
animation = [CCAnimation animationWithSpriteFrames:animFrames delay:0.2f];
[sprite runAction:[CCActionRepeatForever actionWithAction:[CCActionAnimate actionWithAnimation:animation]]];
CCActionRepeatForever,CCActionAnimate .. http://www.cocos2d-iphone.org /api-ref/3.0-rc1/ – LearnCocos2D
你也可以使用CCAnimatedSprite,它使得它非常簡單:https://www.makegameswith.us/gamernews/331/ccanimatedsprite-the-easiest-way -to-動畫-A-SPR –