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

2013/12/11

Scoreboard numbers

Winkan Winkan

2013/12/11

#
Hello, ive made a code for my scoreboard and everything works fine, but i have these "boxes" that i want the score in, something like that, but now i have 212 all over the place, but i need to wider the space between the numbers my code so far is setImage(new GreenfootImage(100, 100)); getImage().clear(); getImage().setColor(Color.RED); getImage().setFont(new Font("Calibri", Font.BOLD, 30)); getImage().drawString(""+num, 60, 60);
danpost danpost

2013/12/11

#
Please elaborate. Correct me if I am wrong. You want your numbers to appear maybe like what you would see when you view a baseball scoreboard where the runs for each inning are shown on separate placards. Also, I cannot say whether you mean 'two-hundred twelve' or 'two-one-two' (as a single number or three separate numbers).
Winkan Winkan

2013/12/12

#
oh im sorry if i were a bit vague, okey i have this picture, with boxes, where the scoreboard is. and it looks kinda like this and the problem is that the numbers gets over the pictures, and i want to create distance beetween the numbers so they are in all three boxes, instead of three numbers being in one and a half box
Winkan Winkan

2013/12/12

#
so i want to create a width x between every numbers
danpost danpost

2013/12/12

#
I will have to presume that you have one 'int' field that holds a number that could be in the hundreds.
int num = 345; // arbitrary value for your number
int wide = 60; // adjust to width of '[_][0][_]'
String str = "  "+num; // turned to at least a 3-character string with leading spaces
str = str.substring(str.length()-3); // adjusted to exactly a 3-character string
GreenfootImage image = new GreenfootImage(wide, 20); // adjust height, '20', to appropriately value (main image)
for (int d=0; d<3; d++)
{
    GreenfootImage glyph = new GreenfootImage(""+str.charAt(d), 20, java.awt.Color.red, null); // adjust '20' to appropriate value for font size (digit image)
    image.drawImage(glyph, image.length()*(d*2+1)/6-glyph.length()/2, 0);
}
setImage(image);
Winkan Winkan

2013/12/13

#
thanks will try it out! :)
You need to login to post a reply.