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

2015/10/24

GreenfootImage Troubles

DogeOverlord DogeOverlord

2015/10/24

#
So I have this class, Textbox, and I am trying to display two lines of text on it, but drawString() and drawImage() don't appear to be doing anything. Here is the relevant code"
GreenfootImage Background = new GreenfootImage("White600x100.png");
setImage(Background);
GreenfootImage Line1 = new GreenfootImage(line1,25,Color.BLACK,new Color(0,0,0,0));
GreenfootImage Line2 = new GreenfootImage(line2,25,Color.BLACK,new Color(0,0,0,0));
Background.drawImage(Line1,300,300);
Background.drawImage(Line2,300,350);
setImage(Background);
And I also tried
GreenfootImage Background = new GreenfootImage("White600x100.png");
setImage(Background);
Background.setColor(Color.BLACK);
Background.drawString(line1,300,300);
if(line2 != null) Background.drawString(line2,300,350);
setImage(Background);
Any help?
danpost danpost

2015/10/24

#
The name of the image file you use for the background image suggests that it is only 100 pixels high. Having the other images drawn at 300 and 350 pixels down from the top edge will end up off the image leaving your original image unchanged.
DogeOverlord DogeOverlord

2015/10/25

#
The Textbox is covering 300-400 though
danpost danpost

2015/10/25

#
DogeOverlord wrote...
The Textbox is covering 300-400 though
But, what is the size of the image stored in the "White600x100.png" file? That would be the relevant thing. Maybe you are thinking that since you set the world background to that image, then the image of the background of the world is the same image. This is not the case, however. When you set an image to the background of the world, the image is drawn over the current background image and tiled if needed to fill it. Your world may have 400 or more rows of pixels in it; but, to reference that background image, you need to use the following after setting the image to the background:
Background = getBackground();
Then, you can draw your line images onto the background image of the world.
DogeOverlord DogeOverlord

2015/10/25

#
After playing around with it a bit with an image size of 600 by 400 (Size of the world) I discovered that the drawString coordinates are relative to the top left of the GreenfootImage, so I adjusted it and got it working. Also Textbox is an actor, not a world. Background refers to the background of the textbox. EDIT: And of course if I had looked at the documentation closer I would have known that...
You need to login to post a reply.