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

2015/3/25

Changing Text size

Leenza Leenza

2015/3/25

#
]
public class Loser extends World
{

    /**
     * Constructor for objects of class Loser.
     * 
     */
    public Loser()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(600, 400, 1); 
        showMessage();
    }
    public void showMessage()
    {
        GreenfootImage bg = getBackground();
        bg.setColor(Color.YELLOW);
        bg.drawString("You Lose", 300, 200);
    }
}
I have the above code in my game. It does show the text "you lose" like I want it too. However, it is very small. I want to make the text bigger. How do I do that?
danpost danpost

2015/3/25

#
You could change the Font object that the background image uses before drawing the String content on it. However, I find it much easier to just create a different image using the GreenfootImage constructor that requires the size and colors used to render the text and draw that image onto the background image:
GreenfootImage image = new GreenfootImage("You Lose", 120, Color.YELLOW, null);
getBackground().drawImage(image, 300-image.getWidth()/2, 200-image.getHeight()/2);
Leenza Leenza

2015/3/25

#
danpost wrote...
You could change the Font object that the background image uses before drawing the String content on it. However, I find it much easier to just create a different image using the GreenfootImage constructor that requires the size and colors used to render the text and draw that image onto the background image:
GreenfootImage image = new GreenfootImage("You Lose", 120, Color.YELLOW, null);
getBackground().drawImage(image, 300-image.getWidth()/2, 200-image.getHeight()/2);
Where exactly would I put this code? Would I put it where I currently have
GreenfootImage bg = getBackground();
        bg.setColor(Color.YELLOW);
        bg.drawString("You Lose", 300, 200);
or somewhere else (sorry I am a beginner)
danpost danpost

2015/3/25

#
Leenza wrote...
Where exactly would I put this code? Would I put it where I currently have < Code Omitted > or somewhere else (sorry I am a beginner)
Yes, it would replace those exact lines.
You need to login to post a reply.