1

当我这样做时:

[gameLayer pauseSchedulerAndActions];

大多数游戏会暂停,但正在进行此操作的精灵不会暂停旋转:

[sprite runAction:[CCRepeatForever actionWithAction:[CCRotateBy actionWithDuration:5.0 angle: 360]]];

此外,那些运行 CCAnimations 的精灵不会停止动画:

CCAnimation *theAnim = [CCAnimation animationWithSpriteFrames:theFrames delay:0.1];
CCSprite *theOverlay = [CCSprite spriteWithSpriteFrameName:@"whatever.png"];                
self.theAction = [CCRepeatForever actionWithAction:[CCAnimate actionWithAnimation:theAnim]];

游戏暂停时如何让这些暂停?我希望“pauseSchedulerAndActions”能够暂停操作,但似乎并非如此。

4

2 回答 2

4

pauseSchedulerAndActions 不是递归的,因此它只会影响您正在暂停的节点上的操作和计划,而不是子节点。

如果您的场景/层很浅,您可能只需遍历层的子层并在每个层上调用 (pause/resume)SchedulerAndActions 即可,否则,如果您有更深的图,您可能希望递归地调用它。我写了一个小测试,这对我有用:

-(void) pauseSchedulerAndActions: (BOOL) pause forNodeTree:(id)parentNode shouldIncludeParentNode:(BOOL)includeParent
{
    if(includeParent)
    {
        (pause) ? [parentNode pauseSchedulerAndActions] : [parentNode resumeSchedulerAndActions];
    }

    for( CCNode *cnode in [parentNode children] )
    {
        (pause) ? [cnode pauseSchedulerAndActions] : [cnode resumeSchedulerAndActions];

        if(cnode.children.count > 0)
        {
            [self pauseSchedulerAndActions:pause forNodeTree:cnode shouldIncludeParentNode:NO]; // on recurse, don't process parent again
        }
    }
}

所以在你的情况下,你可以尝试调用这个方法并传入你的 gameLayer

于 2013-09-27T17:40:08.823 回答
2

Try [[CCDirector sharedDirector] pause];It 应该暂停所有动画和动作。

于 2013-09-27T17:21:40.070 回答