LibGDX:粒子尺度

Posted

技术标签:

【中文标题】LibGDX:粒子尺度【英文标题】:LibGDX: Particle scale 【发布时间】:2012-03-31 07:08:27 【问题描述】:

在我的游戏中我使用

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

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

//皮尤实验室

【问题讨论】:

【参考方案1】:
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);

【讨论】:

【参考方案2】:

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

- 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

【讨论】:

这个和所有其他的都不能使用最新的库,有什么帮助吗? 就我个人而言,我有一段时间没有使用 libgdx,抱歉:(.【参考方案3】:

嗯,你可以使用粒子编辑器并在那里调整大小:

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

【讨论】:

【参考方案4】:

我使用了与 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();

【讨论】:

【参考方案5】:

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

【讨论】:

以上是关于LibGDX:粒子尺度的主要内容,如果未能解决你的问题,请参考以下文章

Libgdx - 如何旋转 3d 粒子的发射轨迹

Libgdx之粒子系统

Libgdx之粒子系统

Libgdx - 如何仅在按住鼠标按钮时产生粒子?

libGDX ParticleEffect 运行时速度变化

Libgdx 游戏在 Android 上崩溃