6

我用 libgdx 在我的 android 设备上引起了轰动:

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);
    ...
}

我可以以编程方式旋转、设置速度或缩放效果吗?

4

2 回答 2

6

我通过使用此代码作为基础找到了粒子效果旋转问题的解决方案 http://badlogicgames.com/forum/viewtopic.php?f=11&t=7060#p32607

并添加一个小的变化来保存效果的幅度。希望能帮助到你。

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);       
        }
    }
}
于 2015-04-08T22:51:20.640 回答
5

是的。查看 ParticleEmitterTest:https ://github.com/libgdx/libgdx/blob/master/tests/gdx-tests/src/com/badlogic/gdx/tests/ParticleEmitterTest.java

你只需要获得一个 ParticleEmitter:

emitter = effect.getEmitters().first();
emitter.getScale().setHigh(5, 20);
于 2013-02-19T15:56:58.787 回答