LiquidFun渲染粒子

时间:2016-08-31 13:56:12

标签: java libgdx box2d liquidfun

我使用LiquidFun来模拟水,它是基于使用粒子的box2d的物理引擎。我的问题是渲染具有特定颜色的粒子。

在粒子颜色定义上设置粒子颜色的目的是什么?当你还需要设置粒子在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

如果我将粒子设置为红色,它仍将呈现为蓝色,因为ParticleDebugRenderer设置为蓝色。

1 个答案:

答案 0 :(得分:2)

查看源代码,我们可以找到2个渲染器。

ParticleDebugRenderer.javaColorParticleRenderer.java

它们之间的代码差异在于ColorParticleRenderer从ParticleSystem获取颜色,而ParticleDebugRenderer从constuctor获取颜色。

主要用途是我们每次调试时都使用ColorParticleRenderer。我们想要调试粒子时使用ParticleDebugRenderer。我们使用它,因为我们不想在ParticleSystem的定义中更改颜色,因为

  1. 可能有一个定义的粒子系统,因此在定义中改变颜色将毫无意义。
  2. 更改一行图纸比一行定义更容易(你不要说:哦,我忘记了我在定义中更改了颜色
  3. 您的混淆来自于您在未进行调试时使用ParticleDebugRenderer,因此您将相同的颜色分配两次。

相关问题