Cocos2d-动作和动画未暂停 [英] Cocos2d - Actions and Animations are not paused

查看:115
本文介绍了Cocos2d-动作和动画未暂停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做时:

[gameLayer pauseSchedulerAndActions];

大多数游戏都暂停,但是正在进行此操作的子画面不会暂停旋转:

Most of the game pauses, but the sprites that are undergoing this action do not pause spinning:

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

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

Also, those sprites that are running CCAnimations do not stop animating:

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

如何在游戏暂停时让它们暂停?我希望"pauseSchedulerAndActions"可以暂停操作,但事实并非如此.

How can I get these to pause when the game is paused? I would expect "pauseSchedulerAndActions" to pause actions, but that doesn’t seem to be the case.

推荐答案

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

pauseSchedulerAndActions is not recursive, so it will only affect actions and schedules on the node you are pausing, not it's children.

如果场景/图层较浅,则可能只需要循环遍历该图层的子级并在每个图层上调用(pause/resume)SchedulerAndAction,否则,如果您有更深的图,则可能需要调用它是递归的.我写了一个小测试,对我有用:

if your scene/layer is shallow, you could probably just get away with looping through the layer's children and calling (pause/resume)SchedulerAndActions on each, otherwise, if you have a deeper graph, you'll probably want to call it recursively. I wrote up a small test and this worked for me:

-(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

so in your case you could try calling this method and passing in your gameLayer

这篇关于Cocos2d-动作和动画未暂停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆