LibGDX:粒子尺度

时间:2012-03-14 19:05:22

标签: java android libgdx particles

在我的游戏中,我使用

static final float FRUSTUM_WIDTH = 10;
 static final float FRUSTUM_HEIGHT = 15;   

因此,当我绘制粒子时,它们占据整个屏幕并且非常大!那么我该如何缩小它们以满足我的需求?

// Pew Labs

5 个答案:

答案 0 :(得分:25)

ParticleEffect pe = new ParticleEffect();
    pe.load(Gdx.files.internal("data/particle/particle.p"), Gdx.files.internal("data/particle"));
    pe.setPosition(x, y);

    float pScale = 0.2f;

    float scaling = pe.getEmitters().get(0).getScale().getHighMax();
    pe.getEmitters().get(0).getScale().setHigh(scaling * pScale);

    scaling = pe.getEmitters().get(0).getScale().getLowMax();
    pe.getEmitters().get(0).getScale().setLow(scaling * pScale);

    scaling = pe.getEmitters().get(0).getVelocity().getHighMax();
    pe.getEmitters().get(0).getVelocity().setHigh(scaling * pScale);

    scaling = pe.getEmitters().get(0).getVelocity().getLowMax();
    pe.getEmitters().get(0).getVelocity().setLow(scaling * pScale);

答案 1 :(得分:5)

要么你使用粒子编辑器(说实话我不认为这对粒子的大小是一个好主意,因为你提到粒子不会太小(对于我真正推荐的其他东西)或者你只需打开粒子效果文件。它应该由编辑器生成,或者您可以从示例中复制它。在此文件中搜索以下字段:

- Scale - 
lowMin: 0.0
lowMax: 0.0
highMin: 0.6
highMax: 0.6
relative: false
scalingCount: 1
scaling0: 1.0
timelineCount: 1
timeline0: 0.0

根据需要调整highMinhighMax

答案 2 :(得分:2)

好吧,您可以使用粒子编辑器并调整其大小:

http://www.badlogicgames.com/wordpress/?p=1255

答案 3 :(得分:2)

我使用了与Victor相同的方法,但对我有用的是:

    ParticleEffect effect = new ParticleEffect();
    effect.load(Gdx.files.internal("particle/version1.p"), Gdx.files.internal("particle"));
    effect.setPosition(x, .y);
    float pScale = 0.02f;
    float scaling;
    Array<ParticleEmitter> emitters = effect.getEmitters();
    for (ParticleEmitter e : emitters) {

        scaling = e.getScale().getHighMax();
        e.getScale().setHigh(scaling * pScale);

        scaling = e.getScale().getLowMax();
        e.getScale().setLow(scaling * pScale);

        scaling = e.getVelocity().getHighMax();
        e.getVelocity().setHigh(scaling * pScale);

        scaling = e.getVelocity().getLowMax();
        e.getVelocity().setLow(scaling * pScale);

        scaling = e.getSpawnHeight().getHighMax();
        e.getSpawnHeight().setHighMax(scaling * pScale);

        scaling = e.getSpawnHeight().getLowMax();
        e.getSpawnHeight().setLowMax(scaling * pScale);

        scaling = e.getSpawnHeight().getHighMin();
        e.getSpawnHeight().setHighMin(scaling * pScale);

        scaling = e.getSpawnHeight().getLowMin();
        e.getSpawnHeight().setLowMin(scaling * pScale);

        scaling = e.getSpawnWidth().getHighMax();
        e.getSpawnWidth().setHighMax(scaling * pScale);

        scaling = e.getSpawnWidth().getLowMax();
        e.getSpawnWidth().setLowMax(scaling * pScale);

        scaling = e.getSpawnWidth().getHighMin();
        e.getSpawnWidth().setHighMin(scaling * pScale);

        scaling = e.getSpawnWidth().getLowMin();
        e.getSpawnWidth().setLowMin(scaling * pScale);

        scaling = e.getXOffsetValue().getLowMax();
        e.getXOffsetValue().setLowMax(scaling * pScale);

        scaling = e.getXOffsetValue().getLowMin();
        e.getXOffsetValue().setLowMin(scaling * pScale);

        scaling = e.getYOffsetValue().getLowMax();
        e.getYOffsetValue().setLowMax(scaling * pScale);

        scaling = e.getYOffsetValue().getLowMin();
        e.getYOffsetValue().setLowMin(scaling * pScale);
    }
    effect.start();

答案 4 :(得分:0)

我个人使用ScalingViewport来根据用户的屏幕处理我的粒子大小,它可以使您以固定的大小工作,并且它将根据设备的屏幕大小自动缩放。我通常将ScalingViewport中的Scaling.fill放在其构造函数中;这样可以防止粒子拉伸并看起来很糟。