Reputation: 21
I was fooling around in Java,when I decided to make a font class, and my own fonts. Everything prints all right, but when I type "Hello World" into the code, the program shows "Hello Xorld!". I tried switching the X and W, but then it shows "Hello Yorld", and so on. Any fixes?
Also, when I try to type in Hello Xorld, it spits out "Hello Yorld".
public class Font {
private static String chars="ABCDEFGHIJKLMNOPQRSRTUVWXYZ 0123456789.,:;'\"!?$%()-=+/ ";
public static void render (String msg,Screen screen,int x,int y,int colour){
msg= msg.toUpperCase();
for (int i=0;i<msg.length();i++) {
int charIndex= chars.indexOf(msg.charAt(i));
if (charIndex>=0)screen.render(x+(i*8), y, charIndex+30*32, colour);
}
}
}
In a different class:
Font.render("Hello World 0157",screen,0,0,Colours.get(000,-1,-1,555));
Upvotes: 0
Views: 61
Reputation: 5741
In your char[] array, you have this:
....ABCDEFGHIJKLMNOPQRSRTUVWXYZ....
. ^
Note the extra R that comes after the S. Change this to:
ABCDEFGHIJKLMNOPQRSTUVWXYZ
Otherwise every letter after that S will be one out of position.
Upvotes: 3