1. create a batchnode like with the picture created by Textures Paker
CCSpriteBatchNode *spriteSheet =[CCSpriteBatchNode batchNodeWithFile:@"AnimBear.jpg"]; |
2. cache sprite frames with plist (also created together with above)
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"AnimBear.plist"] |
3. create a array with frame like:
NSMutableArray*walkAnimFrames =[NSMutableArray array]; for(int i =1; i <=8; ++i){[walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"bear%d.jpg", i]]]; } |
4. Create an animation:
CCAnimation *walkAnim =[CCAnimation animationWithFrames:walkAnimFrames delay:0.1f]; |
(till now, you can use this animation to play it by action, but this is not the way I want. I want to control this annimation by myself)
*here comes the better part:
5. Add CCAnimation to CCAnimationCache with addAnimation with name
6. create a sprite with first frame [CCSprite spriteWithSpriteFrameName:@"bear1.jpg"]
7. use this below msg to update the frame as will
- (void) setDisplayFrameWithAnimationName: |
|
(NSString *) |
animationName |
index: |
|
(int) |
frameIndex |