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\$

2 Answers 2

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\$
2
  • \$\begingroup\$ I ended up doing the same :) \$\endgroup\$ Aug 13, 2014 at 9:53
  • \$\begingroup\$ For better undestanding this, see also ParticleEffectPool class \$\endgroup\$
    – Aleris
    Jan 28, 2016 at 12:30

You must log in to answer this question.

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