暂停CCAction cocos2d

时间:2012-04-09 16:39:33

标签: iphone ios cocos2d-iphone

self.boxesOnLift = [NSMutableArray array];
        [self init];
        [[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Animation.plist"];
        NSMutableArray *walkAnimFrames = [NSMutableArray array];
        for(int i = 1; i <= 9; ++i) 
        {
            [walkAnimFrames addObject:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:
              [NSString stringWithFormat:@"lift%d.png", i]]];
        }
        self.animation = [CCAnimation animationWithFrames:walkAnimFrames delay:0.1f];
        self.lift = [CCSprite spriteWithSpriteFrameName:@"lift1.png"];        
        self.lift.position = ccp(0, 0);
        self.walkAction = [CCRepeatForever actionWithAction: [CCAnimate actionWithAnimation:walkAnim restoreOriginalFrame:NO]];
        [self.lift runAction:_walkAction];
        [self addChild:self. lift];

我可以暂停当前位置的动画吗?我可以在这个位置恢复行动吗?

2 个答案:

答案 0 :(得分:2)

您需要在要暂停的CCNode上调用-(void) pauseSchedulerAndActions-(void) onExit。请注意,当您添加/删除节点时,此方法可能会产生副作用。

答案 1 :(得分:0)

您还可以使用 - (void)resumeSchedulerAndActions来恢复调度程序及其操作。