Search code examples
c++cocos2d-iphonecocos2d-x

cocos2d-x how to pause a layer's actions and schedule, and then resume them


I have a scene contains many layer(the layer contains many sprite), how can I pause the schedule and actions , but then I can resume them.


Solution

  • Use functions:

    void CCNode::pauseSchedulerAndActions();
    void CCNode::resumeSchedulerAndActions();
    

    If you want all the layer's children to pause, you need a loop to do do this.

    CCArray* childs = this->getChildren();
    CCObject* child;
    CCARRAY_FOREACH(childs, child)
    {
       CCSprite *sprite = (CCSprite *)child;
       child -> pauseSchedulerAndActions();
    }
    

    If you just want a special child to pause;Just use function getChildByTag to get the child and pause the sprite's action.

    Hope it will be helpful :)