cocos2d-x如何暂停和恢复图层的动作和计划?

6

我有一个场景包含许多层(每个层都包含许多精灵),如何暂停计时器和动作,但之后又可以恢复它们。

3个回答

6

使用函数:

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

如果您希望所有图层的子元素暂停,您需要使用循环来实现。
CCArray* childs = this->getChildren();
CCObject* child;
CCARRAY_FOREACH(childs, child)
{
   CCSprite *sprite = (CCSprite *)child;
   child -> pauseSchedulerAndActions();
}

如果您只想暂停一个特定的子节点;只需使用函数getChildByTag获取该子节点并暂停精灵的动作。
希望对您有所帮助 :)

但是有些精灵正在运行动作,使用 'pauseSchedulerAndActions' 无法暂停这些精灵的动作。 - minji_LT
不适用于v4,因为它们已被删除。 https://dev59.com/v2zXa4cB1Zd3GeqPRDIy#29910037 对我有用。 - David Kroukamp

5
在cocos2dx 3.2中,要暂停动作,请在暂停按钮回调中添加Director::getInstance()->pause();,要恢复请添加Director::getInstance()->resume();
要暂停Chipmunk中物体的物理,请添加以下代码:
for (auto nod :this->getChildren()) {

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

并且。
for (auto nod :this->getChildren()) {

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

0

暂停:

pauseSchedulerAndActions();

unscheduleAllSelectors();

恢复:

resumeSchedulerAndActions();

scheduleUpdate();


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接