今晚查了下资料,发现有很多版本,但都大同小异,自己参照代码做了一个例子
准备工作:
1、用Flash制作好每帧的png图片;
2、用Zwoptex或texturepacker生成 .png 和 .plist 文件;
把 .png 和 .plist 文件导入到工程中,剩下的就只剩编码了:
- //在 .h 中:
- NSMutableArray *arr;
- CCSprite *anim;
- CCSpriteBatchNode * _batchNode;
- //在.m 中:
- CGSize size = [[CCDirector sharedDirector] winSize];
- _batchNode = [CCSpriteBatchNode batchNodeWithFile:@"game.png"];
- [self addChild:_batchNode];
- [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"game.plist"];
- arr = [NSMutableArray array];
- for (int i = 235; i <= 353; i++) {
- CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"game-%d.png",i]];
- [arr addObject: frame];
- }
- anim = [CCSprite spriteWithSpriteFrameName:@"game-235.png"];
- anim.position = ccp(size.width/2, size.height/2);
- [self addChild:anim];
- CCAnimation *animation = [CCAnimation animationWithFrames:arr delay:0.3f];
- CCAnimate *animate = [CCAnimate actionWithAnimation:animation];
- [anim runAction:animate];