Hello.
as the tittle says, i am looking for a pause feature, so that i can get all child in the nodes to be paused.
I think you want to use the Node::doEnumerateRecursive
function
In cocos2dx-2.x I had a recursive function like this that did the trick:-
void Game::pauseNodeAndDescendants(CCNode* pNode)
{
pNode->pauseSchedulerAndActions();
CCObject* pObj = nullptr;
CCARRAY_FOREACH(pNode->getChildren(), pObj)
pauseNodeAndDescendants((CCNode*)pObj);
}
not sure why, i keep getting this error on the V3
error C2039: ‘data’ : is not a member of ‘cocos2d::Node’
What code does the error point to?
the CCARRAY_FOREACH
how do i actually call this function…
i called it like this pauseNodeAndDescendants(this);
You’re probably using V3 of cocos2dx and @IslandPlaya’s code is for V2. The main difference here is that V3 uses Vectors instead of CCArrays. CCArrays have a member called ‘data’, where as Vectors do not. If you want to convert his V2 code to V3, it would look something like this:
void Game::pauseNodeAndDescendants(Node *pNode)
{
pNode->pauseSchedulerAndActions();
for(const auto &child : pNode->getChildren())
{
this->pauseNodeAndDescendants(child);
}
}
Thank you so much for this works now
Edit:-
have another proble now… cant resume… seems like even the event listener is paused
Yes, the pauseSchedulerAndActions()
method looks like this in CCNode.cpp:
void Node::pause()
{
_scheduler->pauseTarget(this);
_actionManager->pauseTarget(this);
_eventDispatcher->pauseEventListenersForTarget(this);
}
void Node::pauseSchedulerAndActions()
{
pause();
}
So instead of calling Node::pauseSchedulerAndActions()
, you could just pause the action manager, which is probably what you want, right?
Awesome… pretty much sorts out everything… thanks a lot…