hey,
it’s possible to pause() & resume() a node,
but is it somehow also possible to ask if it is currently paused or active?
e.g. node->IsActive()…
hey,
it’s possible to pause() & resume() a node,
but is it somehow also possible to ask if it is currently paused or active?
e.g. node->IsActive()…
Node::onEnter() and Node::onExit()
To query its active status use Node::isRunning()
Use them with caution
Depends what you define as active.
onEnter() and onExit() are called when a Node is added or removed from the active scene, and isRunning() denotes this state.
The pause() resume() methods on Node currently perform 3 tasks, pause/resume: scheduled functions, actions and event listeners. Therefore to test if a Node is truly paused you would need to query each of these systems (Scheduler, ActionManager and EventDispatcher), but the Node may have some paused and others not, so should isActive() return true when some or all are marked as paused? I think this ambiguity is why we don’t have a isActive() method.
For the sake of an example lets assume that you’re wanting to only know whether or not a Node is being updated. If you’ve scheduled the Node’s update via the scheduleUpdateX() methods, you can query this state as well as pause/unpause the Node via the scheduler.
auto scheduler = node->getScheduler();
scheduler->pauseTarget(node);
scheduler->resumeTarget(node);
scheduler->isTargetPaused(node);
See the Node and Scheduler source for more details on how this works.
Hope this helps!
hmm ok,
are child paused if the parent calls pause()?
and i tried to pause a node
node->pause();
node->getScheduler()->isTargetPaused(node);
isTargetPaused = false??
it should be true 
Calling pause will not pause children.
Calling those methods one after another should yield true indeed. No idea why they’re not. I’d recommend putting a breakpoint on the pause call and stepping through the cocos source to see what’s going wrong.
so, i have to pause all the childs myself ?
It really depends on what you’re trying to achieve.
onEnter() and onExit() call pause() and resume() respectively. They are also recusive, meaning all childen and children’s children, etc will also have their onEnter/onExit methods called. Adding/removing a node to/from the active scene will trigger an onEnter/onExit call.
However when a node is not part of the active scene it will not be rendered. So if you simply want to pause the functionality of a Node, but but still render it, you will need to pause the hierarchy yourself.
Something like this:
void pauseRecursive(Node* _node, bool _pause)
{
if(_pause)
{
_node->pause();
}
else
{
_node->resume();
}
auto& children = _node->getChildren();
for (size_t i = 0; i < children.size(); i++)
{
pauseRecursive(children.at(i), _pause);
}
}
yeah recursion is a good idea, that works for me.