Cocos2d-x how to pause actions and schedule a layer and then resume them

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

+6
source share
3 answers

Use functions:

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

If you want all the children in the layer to stop, you need a loop to do this.

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

If you just want the special child to pause, just use the getChildByTag function to get the child and pause the sprite.

Hope this will be helpful :)

+6
source

In cocos2dx 3.2 To pause actions add

Director::getInstance()->pause(); in the pause button callback. and Director::getInstance()->resume(); for renewal.

To suspend body physics in a petrel,

 for (auto nod :this->getChildren()) { nod->getPhysicsBody()->setResting(true); } 

and

 for (auto nod :this->getChildren()) { nod->getPhysicsBody()->setResting(false); } 
+4
source

pause:

pauseSchedulerAndActions ();

unscheduleAllSelectors ();

summary:

resumeSchedulerAndActions ();

scheduleUpdate ();

0
source

All Articles