[cocos2d]create annimation sprite controled by ourself

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 

 

posted on   dqshll  阅读(202)  评论(0编辑  收藏  举报

努力加载评论中...

导航

< 2012年8月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8

统计

点击右上角即可分享
微信分享提示