Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX ParticleEffectPool issue

I have a problem with ParticleEffectPool in libGDX - the first effect does not show, but why does it work after that?

Here's the code for setting it up:

 destroyEffect = new ParticleEffect();
 destroyEffect.load(Gdx.files.internal("destroy.txt"), Gdx.files.internal(""));

 pool = new ParticleEffectPool(destroyEffect, 10, 100);
 activeEffects = new Array<ParticleEffectPool.PooledEffect>();

When wanted to show the effect, these call was called:

ParticleEffectPool.PooledEffect effect = pool.obtain();

if (effect != null) {
  effect.setPosition(x, y);
  activeEffects.add(effect);
}

During render():

for (int i = 0; i < activeEffects.size;) {
    ParticleEffectPool.PooledEffect effect = activeEffects.get(i);

    if (effect.isComplete()) {
       pool.free(effect);
       activeEffects.removeIndex(i);
    }
    else {
      effect.draw(batch, deltaTime);
      i++;
    }
}

This seems pretty straight forward to me, but the first time it does not work.

like image 440
Lim Thye Chean Avatar asked Nov 27 '25 11:11

Lim Thye Chean


1 Answers

effect.isComplete() is true immediately after being added to the pool. So it is freed in the render function and there is no chance to be drawn.

I have found that resetting the effect fixes that in my situation.

Please Add effect.reset(); after obtain statement.

like image 129
Ramywhite Avatar answered Nov 29 '25 02:11

Ramywhite



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!