2014-02-06 69 views
0

所以,我想如何在cocos2d 3.0中創建動畫?

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

但後來我發現,CCRepeatForever已被重命名和刪除CCAnimate。我怎樣才能取代這個?

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

+0

CCActionRepeatForever,CCActionAnimate .. http://www.cocos2d-iphone.org /api-ref/3.0-rc1/ – LearnCocos2D

+0

你也可以使用CCAnimatedSprite,它使得它非常簡單:https://www.makegameswith.us/gamernews/331/ccanimatedsprite-the-easiest-way -to-動畫-A-SPR –

回答

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

CCRepeatForever被替代爲CCActionRepeatForeverCCAnimateCCActionAnimate