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

2012/4/5

Creating a nice looking counter

SPower SPower

2012/4/5

#
Hi all, I want to create a counter which's image is made out of a png as background and text on the foreground. Does anyone know how to do this?
danpost danpost

2012/4/5

#
Sure, each time the count on the counter changes: (1) create a new image from the file (2) create an image for the score text (3) draw the score text image on the new file image (4) set this as the new image for the object
nooby123 nooby123

2012/4/5

#
Also for show, you could change the font before you draw the text.
SPower SPower

2012/4/6

#
Ok, but how do I do stap 3: (3) draw the score text image on the new file image I know how to draw text, but not how to do it in front of a .png image.
danpost danpost

2012/4/6

#
You will need to 'import java.awt.Color;' and use the 'new GreenfootImage(String text, int fontSize, Color foreground, Color background)' constructor for the text image using 'new Color(0, 0, 0, 0)' as the background color (which would be a transparent background).
nccb nccb

2012/4/6

#
You might want to download the Greenfoot 2.2.0 beta, and check out the Counter class, available from the Edit->Import Class menu. It does almost exactly what you want, so you can either use it, or learn from how it's written.
SPower SPower

2012/4/6

#
Thanks! I already got the 2.2 beta, but I didn't know that there's a counter class. Thank you for your help! If anybody wants to see the result, look at the Jump! scenario on Greenfoot.
SPower SPower

2012/4/6

#
@nccb thanks so much! This is exactly what I wanted. I just updated the Jump! scenario, so check it out if you want.
nccb nccb

2012/4/6

#
Looks good! If you want a fancier scoreboard to display at the end, you can use the same Import Class function to pull in the ScoreBoard class, which you can display at the end of the scenario.
SPower SPower

2012/4/6

#
@nccb Again, this it great. I won't go back using my own ScoreBoard, this is much, much better. Check it out if you want, I already updated it.
You need to login to post a reply.