Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 551
minji_LT Avatar asked Dec 18 '12 02:12

minji_LT


2 Answers

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

like image 112
PeakCoder Avatar answered Oct 23 '22 18:10

PeakCoder


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); 
}
like image 22
jishnu bala Avatar answered Oct 23 '22 19:10

jishnu bala