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

2018/2/17

Adding text

Acituanbus Acituanbus

2018/2/17

#
So I managed to add text, but for some reason it won't change the color or the size of the text.. any idea why?
        Text text = new Text();
        addObject(text, 694,568);

        GreenfootImage pic = new GreenfootImage(750,10);
        text.setImage(pic);
        text.getImage().drawString("This is a text!", 0, 10);
        text.getImage().setColor(Color.MAGENTA);
        text.getImage().setFont(new Font("Verdana",100));
It doesn't give me any errors or anything at all :/
Vercility Vercility

2018/2/17

#
Manipulate the image first, then set it
danpost danpost

2018/2/17

#
What Vercility means is set the color and font before drawing the string. Also, if the size (height) of the text is to be 100, your image needs to be much taller and the text needs to be drawn much lower than 10 pixels down. Btw, on lines 6 through 8, you can just use 'pic' instead of 'text.getImage()'.
You need to login to post a reply.