0
\$\begingroup\$

I am trying to use a particle system/emitter in Slick2D to produce a thrust jet from a space ship. I can get the emitter running continuously without any problem, however I can't get it to run for a fixed duration when I press the thrust key (which I need to do so that it only emits particles when the thrust is active). Note I can get the emitter to run for a fixed duration once when the program starts, but can't get the emitter to restart afterwards. I have variously tried (all attached to the thrust key press):

  • disabling/re-enabling the configurable emitter
  • resetting the particle system
  • resetting the configurable emitter
  • resetting the State of the configurable emitter
  • replaying the configurable emitter
  • running 2 separate emitters and re-adding these to the particle system when turning the jet on

... which either do nothing (no particles) or give a short burst of particles at the start of the program (for the initial emitter length if emitter length is enabled), but then do nothing whenever I press the thrust key. The last option (running 2 emitters) causes the particle system to run out of particles after about 10 seconds.

Is there a way to stop and restart a particle emitter that will give the effect that I want?

Just to cover any initial questions, I have read and re-read the javadocs (which are, as ever, reductive and unhelpful) and have read what I can find on the internet (mainly FrumsNL videos on youtube, which mention but don't cover this case) as well as doing my own trials as per the list above.

Any help gratefully received.

\$\endgroup\$
1
  • \$\begingroup\$ I forgot to add, I have also tried making the rendering of the particle system dependent on the thrust key being pressed. This works, but it means that the thrust effect (which is running continuously in the background) appears and disappears abruptly. I would prefer to be able to stop and restart the particle effect that that it has a more organic feel... emerging and fading with the thrust key press/release. \$\endgroup\$
    – Twelve1110
    Jan 3, 2015 at 14:39

1 Answer 1

0
\$\begingroup\$

Solved it.

The second line below fixes the problem (I included the first for clarity). By default, if the emitter completes its cycle it is removed from the ParticleSystem. Disabling automatic removal means that you can restart the emitter.

(From my shipflame class)

system = new ParticleSystem(image, 10000);
system.setRemoveCompletedEmitters(false);

I have then just disabled or enabled the length option (which gives a fixed duration to a particle burst if enabled) depending on whether thrust is engaged or not, i.e. if thrust on then disable length, otherwise enable it (I have this set to 10ms in the xml config file). This gives nice, organic puffs of thrust when I 'feather' the thrust control, which is exactly what I wanted.

(From my ship class)

if (this.thrustOn
        && this.engineOn) {
    shipflame.getEmitter().length.setEnabled(false);
    this.applyThrust();
} else {
    shipflame.getEmitter().length.setEnabled(true);
}

For future reference, I had a look at the Slick2D code and resetState() calls replay() and replay() also calls reset(). So, if you want to restart the particle burst use resetState() since that covers all the bases.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .