Search code examples
javalibgdxscaleparticle-system

How to scale particle effects in libGDX at runtime?


Is there any way to scale particle effects at runtime using libGDX's particle system?

I'm aware of this question on the subject, but it doesn't address scaling at runtime. I tried using the answer by Viktor, but it simply made the particle effect disappear all together. Here is the code I tried using:

ParticleEffect pe;

//Scale particle
for(ParticleEmitter emitter : pe.getEmitters())
{
    float scaling = emitter.getScale().getHighMax();
    emitter.getScale().setHigh(scaling * scale);
    scaling = emitter.getScale().getLowMax();
    emitter.getScale().setLow(scaling * scale);
    scaling = emitter.getVelocity().getHighMax();
    emitter.getVelocity().setHigh(scaling * scale);
    scaling = emitter.getVelocity().getLowMax();
    emitter.getVelocity().setLow(scaling * scale);
}

pe.setPosition(x, y);
pe.draw(spriteBatch, delta);

Without the scaling code in the middle of that, it renders fine, just not scaled.


Solution

  • Maybe it's too late... but if someone needs this :

    particleEffect.scaleEffect( scale factor);