Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libgdx particleEffect rotation

I draw fire on my android device with libgdx:

ParticleEffect effect;
ParticleEffectPool fireEffectPool;
Array<PooledEffect> effects = new Array<PooledEffect>();

@Override
public void create() 
{
    ...
    effect = new ParticleEffect();
    effect.load(Gdx.files.internal("particles/fire01.p"), Gdx.files.internal("image"));
    effect.setFlip(true, false);
    fireEffectPool = new ParticleEffectPool(effect, 1000, 3000);

    PooledEffect myEffect = fireEffectPool.obtain();
    myEffect.setPosition(200, 400);
    effects.add(myEffect);
    ...
}

Can I rotate, set speed or scale my effect programmatically?

like image 236
Leo Avatar asked Feb 12 '13 18:02

Leo


2 Answers

I found the solution to the particle effect rotation problem by using this code as base http://badlogicgames.com/forum/viewtopic.php?f=11&t=7060#p32607

And adding a small change to conserve the amplitude of the effect. Hope it helps.

public void rotateBy(float amountInDegrees) {
    Array<ParticleEmitter> emitters = particleEffect.getEmitters();        
        for (int i = 0; i < emitters.size; i++) {                          
           ScaledNumericValue val = emitters.get(i).getAngle();
           float amplitude = (val.getHighMax() - val.getHighMin()) / 2f;
           float h1 = amountInDegrees + amplitude;                                            
           float h2 = amountInDegrees - amplitude;                                            
           val.setHigh(h1, h2);                                           
           val.setLow(amountInDegrees);       
        }
    }
}
like image 186
Aebsubis Avatar answered Oct 15 '22 20:10

Aebsubis


Yes. Check out the ParticleEmitterTest: https://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java

You just need to obtain a ParticleEmitter:

emitter = effect.getEmitters().first();
emitter.getScale().setHigh(5, 20);
like image 26
maxmc Avatar answered Oct 15 '22 20:10

maxmc