在我的 iOS 游戏中,我希望英雄继续奔跑,直到触摸到屏幕并且英雄应该跳跃。所以我写:
在.h文件中:
@interface Hero : CCSprite {
CCSprite *_hero;
id _keepRunning;
}
@property(nonatomic,retain) id keepRunning;
在 .m 文件中:
@synthesize keepRunning = _keepRunning;
-(id) init {
_keepRunning = [CCRepeatForever actionWithAction:[CCAnimate actionWithSpriteSequence:@"heroRun%04d.png"
numFrames:30
delay:0.02f
restoreOriginalFrame:NO]];
}
然后当游戏开始时,我调用run()方法:
-(void) run {
[_hero stopAllActions];
[_hero runAction:_keepRunning];
_heroState = RUNNING;
}
然后我发现CCAnimate actionWithSpriteSequence: numFrames: delay: restoreOriginalFrame:
在 cocos2d v2.0 中已弃用。所以我的问题是,在 cocos2d v2.0 中,我该如何实现这个动画呢?也就是说,让我的英雄继续奔跑?谢谢!
编辑:
我试过这个:
-(CCAnimation*) getMyAnimationWithFramesName:(NSString*)nameFormat numFrames:(int)numFrames delay:(float)delay {
NSMutableArray *frames = [[NSMutableArray alloc] init];
for (int i = 1; i <= numFrames; i++) {
NSString *frameName = [NSString stringWithFormat:nameFormat,i];
[frames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
}
CCAnimation *ani = [CCAnimation animationWithSpriteFrames:frames delay:delay];
return ani;
}
然后在init()中:
_keepRunning = [self getMyAnimationWithFramesName:@"heroRun%04d.png" numFrames:30 delay:0.02f];
在运行()中:
[_hero runAction:[CCAnimate actionWithAnimation:_keepRunning]];
但它仍然不起作用。我应该怎么办?