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

2012/6/13

how to display text

wahaj wahaj

2012/6/13

#
how would I display text using code? also how can I make interactive text? that is when the mouse is clicked on a certain part of the text a piece of code is executed
danpost danpost

2012/6/13

#
No matter how you do it, it will involve an image. There is both a constructor and a method in the GreenfootImage class can be used to create text images. Set an actors image to an image with text and when clicked on you can get the MouseInfo object to determine where exactly the click took place using getX() and getY() on the MouseInfo object.
wahaj wahaj

2012/6/13

#
I made an actor called Text and then I used GreenfootImage image = new GreenfootImage("abc",5,Color.BLACK,Color.WHITE); but when I tried to put the addObject for text in the World constructor it said I cant. I also used (i got this from the greeps scenario) GreenfootImage image = getImage() image.clear() image.drawString("abc:, 250,250) when I try to manually add a Text object it only shows a greenfoot logo instead.I'm trying to make a game which is heavily text based
steved steved

2012/6/13

#
make an actor, import 'java.awt.Color' and in the constructor put this setImage(new GreenfootImage(String, int, Color, Color) replace the 'Color's with your a color first the text color then the background color - some colors are Color.GREEN, Color.ORANGE, Color.WHITE, Color.BLACK.... replace String with your text and the int with the size (start with 25 then increase or decrease to your needs).
danpost danpost

2012/6/13

#
Download my Crayon Babies scenario and look at the 'Option' class. It is pretty much what you need for your Text class.
Baris Baris

2014/11/13

#
I have created an actor called "Instructions" and I have watched "The Joy of Cod episode #22" it explained to me how to display text in Greenfoot and when i entered the code for the text, an error message pops up. can anyone help me Thank You public class Instructions extends Actor { public Instructions() { setImage(new GreenfootImage("Click Run to Start", 20, Color.WHITE, Color.BLACK)); setImage(new GreenfootImage("Controls", "Arrow UP: Move UP", "Arrow Down: Move Down", "Arrow Left: Turn Left", "Arrow Right: Move Right", 20, Color.WHITE, Color.BLACK)); } } public Paper() { addObject (new Instructions()); -> the error comes here. }
danpost danpost

2014/11/13

#
If 'Paper' is your subclass of World, you will need a 'super' constructor call to build your world before the 'addObject' line can add anything to it. You have two 'setImage' lines in your 'Instructions' constructor; however, you can only have one image set to an actor at a time. Also, the second 'setImage' line has multiple string values as arguments; but, the GreenfootImage constructor will only accept one (the first 'setImage' line will not error because it has the proper number and types of arguments).
danpost danpost

2014/11/13

#
You can combine the String values using the '\n' escape sequence as a separator (it indicates a new line of text). This will cause each line to be centered in the image of your Instructions actor, which may not be what you want. As an alternative you can create the image of each line separately and use the 'drawImage' method to put each line exactly where you want them on one main image (you will need to know the width of the widest image and the height of one image times the number of lines to determine the size of the main image -- or, I guess you could create the image using the first way above and get its dimensions to create the main image using the second way.
You need to login to post a reply.