Search code examples
androidlibgdxtextures

Change the color of a texture


is it possible to change a color of a texture to a random color and how can I do that if it's possible? I think another way is to create a sprite sheet with the object in different colors and change the region randomly, but I don't know for sure.


Solution

  • If you have a white texture then you can just change the spritebatch colour to tint the image.

    batch.setColor(new Color(r,g,b,a));
    batch.draw(texture, x, y);
    batch.setColor(new Color(1,1,1,1)); // reset to default colour