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

3

6

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.

Cichocki answered 18/12, 2012 at 2:24 Comment(0)
M
6

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 :)

Meta answered 18/12, 2012 at 2:51 Comment(2)
en, thanks!But there some sprites are running action, use the 'pauseSchedulerAndActions' cannot pause these sprites'action.Cichocki
Doesnt work for v4 as these have been removed. https://mcmap.net/q/1669540/-cocos2d-x-how-to-pause-a-layer-39-s-actions-and-schedule-and-then-resume-them worked for meSamurai
H
5

In cocos2dx 3.2 For pausing actions,add

Director::getInstance()->pause(); in pause button callback. and Director::getInstance()->resume(); to resume.

For pausing physics of a body in Chipmunk add,

for (auto nod :this->getChildren()) {

 nod->getPhysicsBody()->setResting(true); 
}

and

for (auto nod :this->getChildren()) {

 nod->getPhysicsBody()->setResting(false); 
}
Hexameter answered 28/4, 2015 at 3:57 Comment(0)
B
0

pause:

pauseSchedulerAndActions();

unscheduleAllSelectors();

resume:

resumeSchedulerAndActions();

scheduleUpdate();

Britten answered 23/4, 2015 at 16:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.