How do you pause emitted particles

Hi everyone,

I understand that you could pause and resume the Particle System emitter by invoking

emitter->stopSystem(); emitter->resetSystem();

However, is it possible to pause the live particles that are already emitted by the particle system but still within its lifespan (e.g. particles flying out from fireworks, etc) ?

I meet the same problem. Does anyone know a solution?

To pause your game you need something like this:-

void Game::pauseNodeAndDescendants(CCNode* pNode)
{
pNode->pauseSchedulerAndActions();
CCObject* pObj = nullptr;
CCARRAY_FOREACH(pNode->getChildren(), pObj)
pauseNodeAndDescendants((CCNode*)pObj);
}

void Game::resumeNodeAndDescendants(CCNode* pNode)
{
pNode->resumeSchedulerAndActions();
CCObject* pObj = nullptr;
CCARRAY_FOREACH(pNode->getChildren(), pObj)
resumeNodeAndDescendants((CCNode*)pObj);
}

Call the pause function passing your scene/layer that you want to pause and resume to unpause.
This will recursive pause/resume the node graph starting from the passed in parameter.
Hope this helps. (Code for v2.2.x - 3.x should be similar I guess??)

1 Like

For example, I use the particles to show the touches on my game.
I create a new particle emitter on each touch begin. And I call the emitter stop on each touch’s end. The already emitted partile will still work. And then destroy the emitter when it has no particles exist.
So it is work perfectly.
It is just my implemantation.

Thanks for reply. But the function pauseSchedulerAndActions() cannot pause particles. It’s useful for CCActions, but not particles.

What you said is true, but my requirement is to pause the particles which are already emitted. The function stopSystem() will not stop the moving of emitted particles. Any ideas?

Sorry for misunderstanding.
I havn’t met that requirement before. I have no good idea for the problem. May be you can make a subclass of particleSystem to make it more flexible. I also wonder to know the answer .

Well, I’m using a ParticleBatchNode and it most certainly works for that. In fact it works for everything in Cocos2d-x that I’m currently using, which is most types of nodes. The code above is all I use for pausing my whole game, apart from audio handling.
Are you using PartcleBatchNode? You should. Maybe 3.x behaves differently but nobody has specified what version they are using.

“cannot”? I don’t see why pauseSchedulerAndActions() shouldn’t work. In v3 and v2 ParticleSystem derives from Node and updates particles on a scheduled update method.

@IslandPlaya You are right. In c++, your solution works excellent. However, I am using cocod2d-x-lua, and there is no pauseSchedulerAndActions() in CCNode. So I have to call the following code recursively:


actionManager:pauseTarget(node)
scheduler:pauseTarget(node)

Finally it works.

@hunter_hb see above.

@almax27 That’s right. At the beginning I didn’t realize that the particles’ movement is triggered by scheduler, so i only paused all actions, which is not enough. I should pause all scheduler too.

Thanks to all.

1 Like

It’s not working for me at v3.5. There is no pauseNodeAndDescendants func… Have anyone solved this at v3.x?