1
\$\begingroup\$

I am using Libgdx ParticleEffect to draw a fire particle effect .

The issue I have is that when I try to render a ParticleEffect at two different locations within single game loop, only the last draw call has the effect drawn on screen. I update the Particle effect only once per game loop but set its position to two distinct locations and draw it. Is this a trivial problem with Libgdx ParticleEffect:

ParticleEffect effect = new PartcleEffect();
effect.load(gdx.files.internal("data/effect.particle"),atlas,"");
effect.start();

In render :

effect.update(deltaTime);

effect.setPosition(x1,y1);
effect.draw(batch);

effect.setPosition(x2,y2);
effect.draw(batch);

Can someone tell me why it isn't working?

\$\endgroup\$
1
\$\begingroup\$

When you call effect.setPosition(...), it changes the position of all the emitters, but not of the particles. In libGDX, there is currently no way of changing the position of a single particle, so in order to draw particles at 2 locations, you must do the following:

// Pseudo-code
move effect at position 1
add particles
move effect at position 2
add particles
update effect
draw effect

You must create particles at the 2 different locations to achieve the effect you want.

\$\endgroup\$
1
\$\begingroup\$

you have to create an array of pooled effects

Array<PooledEffect> effects = new Array<PooledEffect>();

so, in render(), you draw all effects from array.

for(int i = 0; i < blocos.size();i++){
            if(obj.colision(block.get(i),config)) {

                PooledEffect effect = block.get(i).getEffectPool().obtain();
                effect.setPosition(block.get(i).getX(), block.get(i).getY());
                effects.add(effect);

                blocos.remove(i);
            }

        }
\$\endgroup\$
  • \$\begingroup\$ I ended up doing the same :) \$\endgroup\$ – Rahul Verma Aug 13 '14 at 9:53
  • \$\begingroup\$ For better undestanding this, see also ParticleEffectPool class \$\endgroup\$ – Aleris Jan 28 '16 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.