Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx - How to spawn particles only when I hold mouse button?

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?

like image 597
Pablo1517 Avatar asked Nov 11 '22 16:11

Pablo1517


1 Answers

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);
like image 146
ericn Avatar answered Dec 06 '22 12:12

ericn