Making Power Bars
See here for a video on how to make power bars.
If you find this not engaging or tough to follow, why not just think about it yourself!?
Here's some general info:
To create a blank image...
you need to pass the width and height of the desired image to the GreenfootImage constructor. The image will be completely transparent.
GreenfootImage image = new GreenfootImage(60, 50); //Creates an image 60 pixels wide and 50 pixels high
If you find this not engaging or tough to follow, why not just think about it yourself!?
Here's some general info:
To create a blank image...
you need to pass the width and height of the desired image to the GreenfootImage constructor. The image will be completely transparent.
GreenfootImage image = new GreenfootImage(60, 50); //Creates an image 60 pixels wide and 50 pixels high
Here's an example of how each blank image is set up!
Setting the colour...
Before using any of the drawing methods, you need to tell the image what colour you want to draw in. To do this, call the GreenfootImage object's setColor() method. This takes a Color object from Java's library. The easiest way to get a Color object is to use one of the pre-defined constants in the Color class, such as Color.BLACK. Other colours available include white, gray, red, green, blue, yellow and orange. See the Java API documentation of the Color class for a full list of pre-defined colours and other ways of getting Color objects.
image.setColor(Color.BLACK); //Sets the drawing color to black
Drawing rectangles....
Rectangles can be drawn using the drawRect method. The method takes four parameters: the x and y co-ordinates of the top-left corner of the rectangle, its width and its height. The following code would draw a rectangle 60 pixels wide by 30 pixels high in the top-left corner of the image:
image.drawRect(0,0,60,30);
Note that a FILLED rectangle can be called using fillRect!
Other helpful methods...
image.clear(); //clears what was on the canvas before (so you could redraw your new power bar!)
image.drawString("Your words here", 10,60); //will write out words on your canvas at 10,60
See the GreenfootImage class API for more info!
Before using any of the drawing methods, you need to tell the image what colour you want to draw in. To do this, call the GreenfootImage object's setColor() method. This takes a Color object from Java's library. The easiest way to get a Color object is to use one of the pre-defined constants in the Color class, such as Color.BLACK. Other colours available include white, gray, red, green, blue, yellow and orange. See the Java API documentation of the Color class for a full list of pre-defined colours and other ways of getting Color objects.
image.setColor(Color.BLACK); //Sets the drawing color to black
Drawing rectangles....
Rectangles can be drawn using the drawRect method. The method takes four parameters: the x and y co-ordinates of the top-left corner of the rectangle, its width and its height. The following code would draw a rectangle 60 pixels wide by 30 pixels high in the top-left corner of the image:
image.drawRect(0,0,60,30);
Note that a FILLED rectangle can be called using fillRect!
Other helpful methods...
image.clear(); //clears what was on the canvas before (so you could redraw your new power bar!)
image.drawString("Your words here", 10,60); //will write out words on your canvas at 10,60
See the GreenfootImage class API for more info!