所以在我的游戏中,我想要一个简单的逐帧动画。当我在 init 函数中使用它时,动画效果很好,但是一旦我停止动作并尝试重新启动它,什么都没有发生。
这是在初始化
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Dubstep Dan_default.plist"];
CCSpriteBatchNode *spriteSheet = [CCSpriteBatchNode
batchNodeWithFile:@"Dubstep Dan_default.png"];
[self addChild:spriteSheet];
walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"1-%d.png", i]]];
}
walkAnim = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
self.character = [CCSprite spriteWithSpriteFrameName:@"1-1.png"];
_character.position = ccp(80, 260);
self.walkAction = [CCRepeatForever actionWithAction:
[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
// self.walkAction = [CCAnimate actionWithAnimation:walkAnim];
[_character runAction:_walkAction];
[_walkAction retain];
[spriteSheet addChild:_character];
这是我的游戏勾选功能
if(gp.isControlling && (gp.controlQuadrant == 0 || gp.controlQuadrant == 1) && (_character.position.x < 250))
{
if([_walkAction isDone]) {
[_character runAction:_walkAction];
NSLog(@"TEST");
}
targetX = 7;
_character.scale = 1;
}
else {
[_character stopAction:_walkAction];
targetX = 0;