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

2018/11/2

How do these numbers result in a specific color?

QSABC10 QSABC10

2018/11/2

#
I'm a little confused on how to change the color of my scoreboard. I realize how to change the font color, but the actual color of the rectangle is very confusing to change. Can someone help me?
 private void makeImage(String title, String prefix, int score)
    {
        GreenfootImage image = new GreenfootImage(WIDTH, HEIGHT);

        image.setColor(new Color(255,255,255, 128));
        image.fillRect(0, 0, WIDTH, HEIGHT);
        image.setColor(new Color(0, 0, 0, 128));
        image.fillRect(5, 5, WIDTH-10, HEIGHT-10);
        Font font = image.getFont();
        font = font.deriveFont(FONT_SIZE);
        image.setFont(font);
        image.setColor(Color.YELLOW);
        image.drawString(title, 90, 100);
        image.drawString(prefix + score, 25, 200);
        setImage(image);
    }
danpost danpost

2018/11/2

#
QSABC10 wrote...
How do these numbers result in a specific color? I'm a little confused on how to change the color of my scoreboard. I realize how to change the font color, but the actual color of the rectangle is very confusing to change. Can someone help me? << Code Omitted >>
Please pay specific attention to the Fields and Constructors of the Color class.
bentondecusin bentondecusin

2018/11/2

#
There are two ways to set colours. One way is what your font colour is using, which is
image.setColor(Color.YELLOW);
Greenfoot provides several existed colours like Yellow, White, Red, Pink. You can find these colours on Greenfoot Documentation. Another ways is you make a colour. The method is
  image.setColor(new Color(int a, int b, int c, int d);
or
  image.setColor(new Color(int a, int b, int c);
int a, int b, int c make up the RGB (red, green, blue) code and int d determines the transparency (0 is transpartent and 1 is opaque Hope this helps
You need to login to post a reply.