0
votes

I'm currently trying to flip a particle effect (libgdx API). What works great so far: new created particles got flipped correctly because I changed the parameters of the emitter. But I want to flip already existing particles as well.

Created particles are not available outside the ParticleEmitter class, so I decided to copy the code and duplicate the ParticleEmitter class.

So my code looks like this:

    ParticleEmitter emitter;

    for (int i = 0; i < getEmitters().size; i++) {

        emitter = getEmitters().get(i);


        // change already existing particles:

        Particle[] particles = emitter.getParticles();
        boolean[] active = emitter.getActive();
        for (int j = 0, n = active.length; j < n; j++) {
            if (active[j] == true) {
                Particle particle = particles[j];

                // Here I have to do something with the particle



            }
        }

        // change emitter parameters for new created particles: 

        /*
        *
        *  emitter.setValue(...)
        *
        */
    }

Maybe you have a good idea? Thanks :)

1
I have no idea what you mean by flip particles, even less about what your actual question is. my current idea is more involved in my dinner plans tonight, so sure, I have a good idea, but it's not helpful for you, afaik. just a hint: you may want to learn write code like this: if (active[j] == true) as if (active[j] ) - Stultuske
Thanks, a particle effect is positioned and parameters describe in which direction the emitted particles fly (for example wind or gravity). A particle effect might has more than one emitter, so you have to iterate over them. Then in the bottom part I change the parameters, so all new projectiles get affected by those changes, but the current particles should also be affected by the flip, that's the point I try to figure out. - Lukas__

1 Answers

0
votes

Try scaleSize method of ParticleEmitter if you want to flip all particles:

// Horizontal (X)
emitter.scaleSize(-1, 1);

// Vertical (Y)
emitter.scaleSize(1, -1);

Also you can flip single Particle just using flip(..):

particle.flip(true, false); // X
particle.flip(false, true); // Y