Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Infinite duration for libGDX particle emitter

Tags:

libgdx

I've been trying to make some fire particle emitter with libGDX.

I downloaded an example (http://pastebin.com/cNWs0tt1#). It looks fine, but it eventually ends (the fire extinguishes) and then starts over. I see in the file that is says the duration is 60000ms. So they relied on putting a high number.

Well, that's lame. I tried putting a duration of 0, which of course doesn't work as it just keeps on dying over and over.

So how can I make a particle emitter with unlimited duration?

like image 494
Voldemort Avatar asked Jun 01 '14 04:06

Voldemort


2 Answers

You can set the continous-flag to true, the effect will start over and over again.

In the editor:

set particle effect to continous

Or in the source-file:

- Options - 
attached: false
continuous: true <----------------------------
aligned: false
additive: true
behind: false
like image 101
Manuel Avatar answered Oct 20 '22 02:10

Manuel


I found a simple workaround for what you are trying to accomplish.

effect.findEmitter("youremitter").durationTimer = 0;

If you call this each time the effect is being rendered, you can reset each emitter to it's starting duration timer. I have tested it and it seems to work very nicely.

Do note however that you need to call this line for each one of your emitters. For example, if you have a rocket ship with a flame/smoke particle effect, you should do this.

public void render(float delta) {
    effect.findEmitter("fire").durationTimer = 0;
    effect.findEmitter("smoke").durationTimer = 0;
    // Render your particle effect here
}

I hope this helps, good luck!

like image 20
BigBerger Avatar answered Oct 20 '22 04:10

BigBerger