How to animate CCSprite in Cocos2D 3.x?

Do you know how to revitalize CCSprite in the new Cocos2D v3.x ?

Many classes have changed, and the old method seems to be inoperative.

 NSMutableArray *animFrames = [NSMutableArray array]; for(int i = 1; i <= 3; i++) { CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"Sprite-%d.png",i]]; [animFrames addObject:frame]; } CCAnimation *animation = [CCAnimation animationWithName:@"run" delay:0.1f frames:animFrames]; [mySprite runAction:[CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:animation restoreOriginalFrame:NO]]]; 

any idea?

thanks.


Additional Information

enter image description here

+7
ios objective-c cocos2d-iphone
source share
2 answers

Here's how it works:

  NSMutableArray *animationFrames = [NSMutableArray array]; for(int i = 1; i <= FRAMES; ++i) { CCSpriteFrame *spriteFrame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName: [NSString stringWithFormat:@"animationFrame%d.png", i]]; // } //Create an animation from the set of frames you created earlier CCAnimation *animation = [CCAnimation animationWithSpriteFrames: animationFrames delay:delay]; //Create an action with the animation that can then be assigned to a sprite CCActionAnimate *animationAction = [CCActionAnimate actionWithAnimation:animation]; CCActionRepeatForever *repeatingAnimation = [CCActionRepeatForever actionWithAction:animationAction]; [self runAction:repeatingAnimation]; 
+5
source share

You can change CCRepeatForever to CCActionRepeatForever .

+1
source share

All Articles