[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 |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步