Pausing / freezing particles possible?

I’m implementing a pause button in my games and I was wondering if it’s possible to pause a particle system and all currently active particles.

I found something for cocos2d-x How do you pause emitted particles but I’m not sure how I would convert that to Creator.

Thanks for any help

1 Like

You reference the cc.ParticleSystem component and then call its stopSystem() method.

onLoad: function () {
   this.particleSystem = this.node.getComponent(cc.ParticleSystem);
},

update: function() {
 if(somecondition === true) {
   this.particleSystem.stopSystem()
}

the only problem I have with this is that it doesn’t actually freeze the particles where they are, it stops the emmision completely

1 Like

I want to actually freeze particles in cocos2d-x 3.16 c++. Is it possible?

Yes, it’s the actual freezing of currently active particles that I have a problem with.

I can access them from this.myParticleSystem['_sgNode']['_particles'] but I don’t know what to do with the individual particles.

ok here’s what I got for you guys -

You need to kill the update method for the particle, that way it doesn’t update anymore but the CCSGParticleSystem class still thinks the particle is alive. Then when you are ready to resume, you need to reset the update method to its proper code:

To freeze -

this.savedUpdate = this.myParticleSystem['_sgNode'].update;
this.myParticleSystem['_sgNode'].update = function () {return}

To resume -

this.myParticleSystem['_sgNode'].update = this.savedUpdate;
1 Like

Excellent. This worked 100%. Thanks a lot.

I made a small helper class for it.

export default class ParticlesExtra {
  static cachedFreezeUpdate;
  static freeze(pa: cc.ParticleSystem) {
    this.cachedFreezeUpdate = pa['_sgNode'].update;
    pa['_sgNode'].update = function () { return }
  }
  static unfreeze(pa: cc.ParticleSystem) {
    pa['_sgNode'].update = this.cachedFreezeUpdate;
  }
}
1 Like

nice, just a side note but i believe cachedFreezeUpdate will essentially be exactly the same for all particles, you only need to grab it once, but each particle will need its _sgNode.update method flipped

but we’re grabbing the _sgNode update, not on the particle itself, if it even has one.

or am I not understanding you correct?

yes you’re right i mean the _sgNode.update (editing comment), since it’s static code there’s nothing there that will be different between particles

1 Like

Is it possible in c++? I need it

There is a link in my first post.

I added a change to the C++ cocos some months ago that adds a method to freeze and unfreeze - if you have a hnt you should be able to find the name of the method. Im not on my Mac right now so can’t look it up.

I found my pull request at https://github.com/cocos2d/cocos2d-x/pull/15836

Thanks. I will look at it

Thanks for sharing!!