我创建了一个像这样的动画
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
我想在特定帧和特定触发器上暂停此动画。然后在特定触发后再次恢复动画。
我尝试使用 stopAction,然后再次使用 runAction。但经过一些迭代后它就停止工作了。我需要再次创建动画和动作才能再次运行该动画。
我尝试使用pauseSchedulerAndAction和resumeSchedulerandAction,但随后游戏暂停,如果我尝试再次触发暂停而不恢复游戏崩溃。
是否有任何东西可以在特定帧上暂停动画并从同一帧再次恢复。
我通过创建 1 帧动画解决了我的问题
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <2; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
我使用上面的代码来暂停我的动画动作。当我想恢复动画动作时添加以下代码。
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:
@"Actor.plist"];
spriteSheet = [CCSpriteBatchNode batchNodeWithFile:@"Actor.pvr.ccz"];
[self addChild:spriteSheet];
NSMutableArray *walkAnimFrames = [NSMutableArray array];
for(int i = 1; i <= 8; ++i) {
[walkAnimFrames addObject:
[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
[NSString stringWithFormat:@"clip000%d.png", i]]];
}
CCAnimation *walkAnim = [CCAnimation
animationWithFrames:walkAnimFrames delay:0.07f];
playWalkSound = [CCCallFuncN actionWithTarget:self selector:@selector(PlayRunningSound:)];
walkAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
[actor runAction:[CCSpawn actions:walkAction, nil]];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)