# Libgdx Palette Swap

I'm developing a game using the Libgdx library.

I'm trying to implement a very simple palette swap functionality (basically just complete recolouring of some areas, I don't even need to have various shades), but I don't have any idea where to begin.

The closest I've come is trying to draw the picture myself using a Pixmap, but that appears to be horrible unmaintainable and produces oodles of code.

I'm not sure if this is what you have already tried, but you can simply get the Pixmap of the Texture and draw over it:

texture.getTextureData().prepare();
Pixmap pixmap = texture.getTextureData().consumePixmap();
for(int i=0; i < pixmap.getWidth(); i++)
{
for(int j =0; j < pixmap.getHeight(); j++)
{
if(pixmap.getPixel(i,j) == colorToReplace)
{
pixmap.drawPixel(i,j,newColor);
}
}
}

• I tried something similar to yours and it worked well. The getPixel returns an integer representing the colour in rgb888 value. Otherwise it worked for my case. Thanks – Haedrian Oct 31 '13 at 19:19