libgdx particleEffect rotation

a 夏天 提交于 2019-12-22 05:26:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!