I'm experimenting with a game that allows you to change the colour of the shirt of your player. I'm using this code:
However, the shirt colours do not change. Does anyone know what I'm doing wrong?
public void setColour(Color colourToOverwrite, Color colourToUse)
{
GreenfootImage currentImage = getImage();
for (int currentPixel = 0; currentPixel < currentImage.getHeight(); currentPixel++)
{
fillRow(colourToOverwrite, colourToUse, currentPixel, currentImage);
}
}
public void fillRow(Color oldColour, Color newColour, int y, GreenfootImage image)
{
for (int currentPixel = 0; currentPixel < image.getWidth(); currentPixel++)
{
if (image.getColorAt(currentPixel, y) == oldColour)
{
image.setColorAt(currentPixel, y, newColour);
}
}
}
