Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX: Particle scale

In my game I use

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

So when I draw the particles they take the whole screen and are huge! So how do I scale them down to fit my needs?

//Pew Labs

like image 865
Pew Labs Avatar asked Mar 14 '12 19:03

Pew Labs


4 Answers

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);
like image 121
Viktor Avatar answered Nov 05 '22 07:11

Viktor


Either you use the particle editor (to be honest I don't think it's a good idea for sizing the particles, as you mentioned the particles won't get too small (for anything else I really recommend it)) or you just open the particle effect file. It should be generated by the editor or you can copy it from the examples. In this file search the fields below:

- 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

Adjust the highMin and highMax as needed.

like image 42
Dominik Bucher Avatar answered Nov 05 '22 05:11

Dominik Bucher


Well, you can use the particle editor and adjust the size there:

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

like image 2
Shivan Dragon Avatar answered Nov 05 '22 06:11

Shivan Dragon


I have used the same approach as Victor but what worked for me:

    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();
like image 2
Sarpe Avatar answered Nov 05 '22 06:11

Sarpe