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

2012/2/2

Text?

1
2
toytttttt toytttttt

2012/2/2

#
Ive seen a scenario which has a make text method to make text of you choice, but I cant seem to use it myself, Help?
danpost danpost

2012/2/2

#
You might want to post the code of the make text method, so we can see what you are asking about. Or at least, point us to the scenario you have seen it in.
toytttttt toytttttt

2012/2/2

#
Actually it's the balloons scenario that comes with the greenfoot download, in the scenarios folder. Sorry for being unclear.
danpost danpost

2012/2/2

#
Are you refering to the makeImage(String title, String prefix, int score) method in the ScoreBoard class?
toytttttt toytttttt

2012/2/3

#
Yes
danpost danpost

2012/2/3

#
That method is for the final 'Game Over' scoreboard. You might want to post what code you have for it, as well as what you use to call the method and from where. Also, explain exactly what is happening (absolutely nothing, an error message ). For best response, it is well to be complete and specific. Also, include what import statements you are using in the class.
Duta Duta

2012/2/3

#
Heres a method of doing it:
//You'll need this import statement:
import java.awt.*;

//And then here's the code:
GreenfootImage img = new GreenfootImage(500, 50);
img.setColor(Color.BLACK); //Change this to the colour of text that you want
float fontSize = 35.0f; //Change this to the font size that you want
Font font = img.getFont().deriveFont(fontSize); //This adjusts the default font to the correct size.
img.setFont(font);
img.drawString("The text that you want", x, y);
setImage(img);
Also, in img.drawString("Text", x, y) x and y are not the positions you might expect: - x is the x position of the first letter. - y is the y position of the bottom of the first letter. Oh and here's the link for the java.awt.Color documentation - look through the fields for a list of default colors you can use. If the color you want to make isn't one of those, then replace "Color.BLACK" with "new Color(int red, int green, int blue, int alpha)" where all of the parameters are in the range 0 <= parameter <= 255 There are other constructors for Color but that's the one I find the most useful. Oh and alpha is the transparency.
Duta Duta

2012/2/3

#
This gave me the inspiration for this scenario :)
toytttttt toytttttt

2012/2/3

#
Thanks, I'll try it out.
toytttttt toytttttt

2012/2/8

#
I did the code you told me, and although it compiles when I run nothing happens. I have put the method in a actor class, is this okay?
sp33dy sp33dy

2012/2/8

#
Hi toyttttt, if you go and download my FileDialog demo. You should be able to easily see how I'm creating the button; which uses the drawString command. http://www.greenfoot.org/scenarios/4120
danpost danpost

2012/2/8

#
Yes, because there is not an object reference preceding 'setImage(..)', it would have to be in the class that you are setting the image for. I say again, for better assistance, please post the code in question. You will find solutions much quicker that way.
danpost danpost

2012/2/8

#
@toytttttt, Yes, sp33dy's method for creating the button would be a fine template for your needs. @sp33dy, I revised your method to
setImage(new GreenfootImage(" Click here for dialog ", 30, Color.BLACK, Color.RED));
sp33dy sp33dy

2012/2/8

#
Neat! Didn't fully look at the constructors..
danpost danpost

2012/2/8

#
Maybe toytttttt can make use of this constructor (instead of getting confused with all the things that need to be done without using it)! How about it, toytttttt?
There are more replies on the next page.
1
2