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.
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.