How to get sprite animation frames using spritesheet in cocos2d

H

if you are using SpriteSheet for animation,you can extract all required frame like this…

    [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"spritesheet.plist"];     CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"spritesheet.png"];     [self addChild:spriteSheet];      NSMutableArray *frames = [[[NSMutableArray alloc]init]retain];      for(int i = 1; i <= numberFrames; i++) {           [frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"%@0%d.png", file_name, i]]];         }      // Animation object with 0.04 seconds between each frame (~30fps)         CCAnimation *anim = [CCAnimation animationWithFrames:frames delay:0.04f];         if(self.sprite){           // Animate the sprite           [self.sprite runAction:[CCAnimate actionWithAnimation:anim restoreOriginalFrame:NO]];          }

 

About the author

anshul.jain
By anshul.jain

Category