如何暂停和恢复应用于 ccSprite 的操作?

how to pause and resume action applied to the ccSprite?(如何暂停和恢复应用于 ccSprite 的操作?)
本文介绍了如何暂停和恢复应用于 ccSprite 的操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类似

        [[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]];

我想在特定帧和特定触发器上暂停此动画.然后在特定触发后再次恢复动画.

I want to pause this animation on particular frame and particular trigger. and then again resume animation after particular trigger.

我尝试使用 stopAction,然后再次使用 runAction.但它在一些迭代后停止工作.我需要再次制作动画和动作才能再次运行该动画.

I tried using stopAction and then again runAction. But it stops working after some iteration. and i need to crate animation and action again in order to run that animation again.

我尝试使用 pauseSchedulerAndAction 和 resumeSchedulerandAction 但随后游戏暂停,如果我尝试再次触发暂停而不恢复游戏崩溃.

I tried using pauseSchedulerAndAction and resumeSchedulerandAction but then game get paused and if i try to trigger pause again without resuming game crashes.

是否有任何东西会暂停特定帧上的动画并从同一帧再次恢复.

is there anything that will pause the animation on particular frame and resum again from same frame.

推荐答案

我通过创建 1 帧动画解决了我的问题

I solved my problem by creating a animation with 1 frame

[[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]];

我使用上面的代码来暂停我的动画动作.并在我想恢复动画动作时添加以下代码.

i used the above code where i want to pause my animation action. and added following code when i want to resume the animation action.

[[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]];

这篇关于如何暂停和恢复应用于 ccSprite 的操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
iOS convert audio sample rate from 16 kHz to 8 kHz(IOS将音频采样率从16 kHz转换为8 kHz)
Enforcing an audio sampling rate in iOS(在iOS中强制音频采样率)
HTTPS request using volley(使用 volley 的 HTTPS 请求)