Thursday, 11 July 2013

Animation png sequence in cocos2d by plist

[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"toon.plist"];
        
 CCSprite *cartoon = [CCSprite spriteWithSpriteFrameName:@"a0001.png"];
 cartoon.position = ccp(s.width/2,s.height/2);
[self addChild: cartoon];
        
NSMutableArray *frames = [[NSMutableArray alloc] init];
for (int i = 1; i <= 10; i++) 
{
NSString *frameName = [NSString stringWithFormat:@"a%04i.png",i];
[frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
        
CCAnimation *a = [CCAnimation animationWithFrames:frames delay:1.0f/24.0f];

[cartoon runAction:[CCAnimate actionWithAnimation:a restoreOriginalFrame:NO]];