如何在cocos2d 3.0中创建动画?

时间:2014-02-06 09:11:10

标签: cocos2d-iphone

所以我试过

self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim]];

但后来我发现CCRepeatForever已被重命名并且CCAnimate已被删除。我该如何替换它?

所有代码:http://pastebin.com/VnrtiCwb

2 个答案:

答案 0 :(得分:1)

CCRepeatForever已替换为CCActionRepeatForeverCCAnimate替换为CCActionAnimate

答案 1 :(得分:0)

试试这段代码

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]]];