cocos2d使用贴图创建动画
准备工作:
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 spriteWithSpr
浙公网安备 33010602011771号