我对cocos2d和o.c编程真的很陌生,我一直在努力弄清楚sprite动画是如何工作的。由于最近的更新,我得到了很多旧代码,这些代码已经不起作用了。
我有以下(一个有3个精灵的精灵表,我想动画)
不知怎么的,它一直在破坏
这是在我的初始化方法中
[[CCSpriteFrameCache sharedSpriteFrameCache ] addSpriteFramesWithFile:@"eno_glasses.plist" ];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eno_glasses.png"];
[self addChild:spriteSheet];
_body = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"eno_glasses02.png"]];
[spriteSheet addChild:_body];
_body.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
NSMutableArray *animFrames = [NSMutableArray array];
for(int i = 1; i < 3; i++) {
CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:[NSString stringWithFormat:@"eno_glasses0%d.png",i]];
[animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithFrames:animFrames delay:0.03f];
CCAnimate* anime = [CCAnimate actionWithAnimation:animation];
[self runAction:anime];
我知道可以找到图像,因为这是有效的(我可以从plist 01,02,03获得图像)
我是不是忘了零分?
[[CCSpriteFrameCache sharedSpriteFrameCache ] addSpriteFramesWithFile:@"eno_glasses.plist" ];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"eno_glasses.png"];
[self addChild:spriteSheet];
_body = [CCSprite spriteWithSpriteFrameName: [NSString stringWithFormat:@"eno_glasses02.png"]];
[spriteSheet addChild:_body];
_body.position = CGPointMake(screenSize.width / 2, screenSize.height / 2);
使用:
[_body runAction:anime];
对于重复(假设一次)
id anime1=[CCAnimate actionWithAnimation:animation];
id delay=[CCDelayTime actionWithDuration:2.0f];
id anime2=[CCAnimate actionWithAnimation:animation];
id twice = [CCSequence actions:anime1,delay,anime2,nil];
[_body runAction:twice];
此外,您可能希望选择"eno_glasses01.png"作为开始帧。