开发者

how to pause and resume action applied to the ccSprite?

I have created an animation like

        [[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]];
    [a开发者_JAVA百科ctor 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.

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.

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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜