2011-07-11 33 views
1

我創建了像如何暫停和恢復應用於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]]; 

我想暫停特定的框架和特定觸發這個動畫的動畫。然後在特定觸發後再次恢復動畫。

我嘗試使用stopAction,然後再次runAction。但它會在一些迭代後停止工作。我需要再次製作動畫和動作才能再次運行該動畫。

我嘗試使用pauseSchedulerAndAction和resumeSchedulerandAction但隨後遊戲暫停,如果我嘗試再次觸發暫停而不恢復遊戲崩潰。

有什麼會暫停特定幀上的動畫並再次從同一幀中重新播放。

回答

1

我用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]]; 

我使用的上述代碼,其中i要暫停我的動畫動作創建動畫解決了問題。並在我想恢復動畫操作時添加以下代碼。

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