Search code examples
colorslibgdxrgbeffectsparticles

Change a ParticleEffect colour in a LibGDX game to a certain RGB value


I created a 2D particle effect with the Particle Editor tool that comes with LibGDX. Then, I needed to change the particle effect colour to a certain RGB colour programatically. For that purpose, I found this method:

myEffect.getEmitters().get(0).getTint().setColors(float [] colours);

My problem is that I don't know how to convert an RGB colour to the proper array values required by that method since I don't know exactly which colour format is used.

In the ParticleEditor, the colour selection format looks like HSV. However, the colour values stored in the resulting *.p file don't seem to match that format.

I wish someone could tell me how to do the conversion.

Thanks


Solution

  • From the Javadocs

    public void setColors(float[] colors)
    

    Parameters colors - the r, g and b values for every timeline position

    It takes the rgb values in float, There is an online convertor which takes HTML color (HEX) and convert them to RGB decimal values and then you can pass them inside your setColors() method.

    Here is the link.

    Convertor