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\$
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\$
  • \$\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 Oct 31 '13 at 19:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.