5

So I slowly got to know how to manipulate particle system and emitter in-game through the code, but there is one simple task I can't get to know how... How can I spawn particles ONLY when I hold the mouse button? I tried a work-around by setting the maxCount of emmiter to 0 when its not pressed but then it either doesnt emit particles at all, or just makes the existing ones disappear immidiately, which looks very unnatural and I don't want it. Is there a way to emit them "manually" in render method?

Pablo1517
  • 73
  • 7

3 Answers3

1

You probably want to do set the Emission scaled value on the particle emitter. You can leave the max count at whatever maximum particle number you want.

To turn off the creation of particles:

emitter.getEmission().setLow(0);
emitter.getEmission().setHigh(0);

To turn it back on:

emitter.getEmission().setLow(10);
emitter.getEmission().setHigh(10);
ericn
  • 173
  • 5
0

Try using a Pool combined with your listeners:

gitHub link

jos_fzr
  • 188
  • 2
  • 10
0

Ok this is what I got to make it work. "blowing" is basically a boolean that is true when holding mouse button and false when not.

if (blowing) {
        effectEmitter.start();
    } else {
        effectEmitter.allowCompletion();
    }
Pablo1517
  • 73
  • 7