This site requires JavaScript, please enable it in your browser!
Greenfoot back
MBX5
MBX5 wrote ...

2013/4/30

Changing the colour of the text

MBX5 MBX5

2013/4/30

#
i got a text that appears black but i want it in a different colour because since my backround is black you cant see it very well
Gevater_Tod4711 Gevater_Tod4711

2013/4/30

#
How do you create the text? There are serval possibilities for doing that. One would be to use the GreenfootImage(String, int, Color, Color) constructor. Then you just have to change the foreground color (the first one in the constructor). If you use the method drawString of the class GreenfootImage you first have to set the current drawing color using setColor(Color). When the color is set to a different color you can use drawString. I think another way would be to use an image from a file. In this case you would have to set the color of every point like this:
public void changeColor(GreenfootImage img, Color currentColor, Color newColor) {
    for (int x = 0; x < img.getWidth(); x++) {
        for (int y = 0; y < img.getHeight(); y++) {
            if (img.getColorAt(x, y).equals(currentColor)) {
                img.setColorAt(x, y, newColor);
            }
        }
    }
}
You need to login to post a reply.