(CGA) Creating a Scoring System Lesson

Creating a Scoring System

All games need a scoring system. The GreenfootImage class has methods for drawing images by using various drawing methods.

Color

Color can be described in two ways, by color name, by RGB numbers or by Hex numbers

To color an object using the color name:

objectname.setColor(Color.colorname);

An example of this would be

ball.setColor(Color.blue);

To color an object using RGB:

To create a color object use the format

Color variableName = new Color(r,g,b)

The first number is the amount of red, the second is the amount of green and the third is the amount of blue.

Color numbers range from 0 to 255.

An example of this would be:

Color c = new Color(123,45,27);

To use this color to set the color of an object you would say

ball.setColor(c);

Adding the transparency or visibility of the object using this color

You can add a fourth number to the color which will determine how transparent the object will be. Simply add a fourth number. 

This number also has to be between 0 and 255. The lower the number the more transparent the object will be.

Color c = new Color(123,45,27,128);

For more methods in the color class you should look at the API for Greenfoot Color Links to an external site. and choose Color from the menu on the left.

Font

You can create your own font objects in greenfoot.

The Constructor for defining a font is

Font(String name, Font.Style, int size)

An example of this is:

Font f = new Font("Ariel", Font.Bold, 12);

Styles can be Bold or Italic

To create a Plain font use false, false instead of Font.style

An example of this would be:

Font f = new Font("Ariel", false,false,12);

There are many more methods you can use with the Font class. To see them all you should visit the API for Fonts in Greenfoot Links to an external site. and choose Font from the menu on the left.

[CC BY 4.0] UNLESS OTHERWISE NOTED | IMAGES: LICENSED AND USED ACCORDING TO TERMS OF SUBSCRIPTION