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

2013/4/30

GreenfootImage > drawString() not working?

rowanto rowanto

2013/4/30

#
I'm trying to add a string on top of Wombat. And for that I've added this method: public void setText() { GreenfootImage image = getImage(); image.setColor(Color.WHITE); image.drawString("XYZ", 0, 0); setImage(image); } but for some reason, it's not working when I run the method no text is shown on top of the wombat image. I've also tried with image.drawString("XYZ", 60, 60); instead of image.drawString("XYZ", 0, 0); Could I have missed something?
davmac davmac

2013/4/30

#
The documentation for the method says:
Draw the text given by the specified string, using the current font and color. The baseline of the leftmost character is at position ( x , y ).
This means that if you draw text at y-position 0, you won't be able to see it - it will be "above" the image. If you draw at (60,60), you are drawing too far to the right (and probably a little bit too low). Try for example (0, 30).
rowanto rowanto

2013/5/1

#
It worked. Thanks a lot!
You need to login to post a reply.