0

I'm using LiquidFun to simulate water, it's a physics engine based on box2d that uses particles. My problem is when rendering the particles with a specific color.

what is the purpose of setting the particle color on it's particle definition? when you also have to set the color on which the particle is to be rendered on the ParticleDebugRenderer.

public void createWater(float x, float y){
        ParticleDef def = new ParticleDef();
        def.color.set(Color.Red); //set particle color
        def.flags.add(ParticleDef.ParticleType.b2_tensileParticle);
        def.flags.add(ParticleDef.ParticleType.b2_colorMixingParticle);
        def.position.set(x, y);
        int index = system.createParticle(def);
    }

ParticleDebugRenderer:

pdr = new ParticleDebugRenderer(Color.BLUE, maxParticles); //set as BLUE

if I set the particle to be RED it would still be rendered in blue because the ParticleDebugRenderer is set to BLUE.

Kevin Bryan
  • 1,846
  • 2
  • 22
  • 45
  • What if you had several waters and you want to debug them? They would be all blue and you woudn't see much? – pr0gramist Aug 31 '16 at 14:02
  • I guess so? but I'm confused on rendering them to a specific color because def.color.set() would be useless because of the ParticleDebufRenderer – Kevin Bryan Aug 31 '16 at 14:08

1 Answers1

2

Looking at the source code we can find 2 renderers.

ParticleDebugRenderer.java and ColorParticleRenderer.java

The code difference between them is that ColorParticleRenderer gets color from ParticleSystem and ParticleDebugRenderer gets color from constuctor.

The main use difference is that we use ColorParticleRenderer everytime we are not debugging. ParticleDebugRenderer is the one to use when we want to debug a particle. We use it, because we don't want to make changes in colors at the definition of ParticleSystem, because

  1. There may be several ParticleSystem of one definition, so changing color in definition would be pointless.
  2. It is easier to change one line of drawing than 1 line of definition (you avoid saying: ohh I forgot that I change the color at the definition)

Your confusion comes from fact that you are using ParticleDebugRenderer when you are not debugging so you assign the same color twice.

pr0gramist
  • 8,305
  • 2
  • 36
  • 48
  • thank you, didn't know there was a colorParticleRenderer. Is there something similar to box2d bodies? alternative to box2dDebugRenderer class. – Kevin Bryan Sep 04 '16 at 15:26
  • I think there is no such thing. It wouldn't have much sense as we rarely draw box2D bodies as shapes filled with color. – pr0gramist Sep 04 '16 at 16:16