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

2019/5/27

How to change font size and colour?

CreatorMoon CreatorMoon

2019/5/27

#
1
getWorld().showText("GG", 24, Color.BLACK, 200, 200);
I am using the above code to try and make coloured and large text for a maze game win screen I am making for school but it keeps saying getWorld is an unknown symbol. Why and how can I fix this? (ASAP would be very appreciated)
Super_Hippo Super_Hippo

2019/5/27

#
You can only use "getWorld" in an Actor subclass. (Unless you have your own "getWorld" method of course.) So if this code is in a World subclass, simply remove "getWorld().". You can't change font size or color using the showText method. The showText method is just a very simple form of text display. For advanced settings, create a GreenfootImage for an actor with everything you want it to show and add this actor into the world.
danpost danpost

2019/5/27

#
Also, unless you wrote your own showText method, you cannot just add a color parameter. In fact, there is no way to change the font size or color of the text produced by showText. You must create your own image and set it to an actor if you do not like how showText displays the text.
CreatorMoon CreatorMoon

2019/5/27

#
Thanks
CreatorMoon CreatorMoon

2019/5/27

#
So if I literally type in "GG" in a large font in Word and set it to my background, it'll do the same thing?
danpost danpost

2019/5/27

#
CreatorMoon wrote...
So if I literally type in "GG" in a large font in Word and set it to my background, it'll do the same thing?
That would probably work; however, you can do it within greenfoot just as well:
1
2
GreenfootImage gg = new GreenfootImage("GG", 240, Color.BLACK, new Color(0, 0, 0, 0));
getWorld().getBackground().drawImage(gg, (getWorld().getWidth()-gg.getWidth())/2, (getWorld().getHeight()-gg.getHeight())/2);
CreatorMoon CreatorMoon

2019/5/27

#
Thanks. I hope to use this next time.
You need to login to post a reply.