问题
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?
回答1:
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);
回答2:
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);
}
}
}
来源:https://stackoverflow.com/questions/14839648/libgdx-particleeffect-rotation