2
\$\begingroup\$

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.

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

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); 
    }
  }
}
\$\endgroup\$
1
  • \$\begingroup\$ 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 \$\endgroup\$
    – Haedrian
    Commented Oct 31, 2013 at 19:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .