I’ve been working on my own game for a while and think that it’s about time that i included my own custom font, like in minecraft, or CatacombSnatch. Does anyone know how to help me out with this?
Look into MatthiasM’s Font Tool (which is part of TWL’s theme editor). It can export a TTF font as a bitmap image with an XML or text file. Then, you simply read the font file and its kerning information and use it when rendering each glyph. For that, look into TWL’s BitmapFont class:
http://hg.picibo.com/twl/file/1055c387f54e/src/de/matthiasmann/twl/renderer/lwjgl/BitmapFont.java
Alternatively, you could simply use TWL or another GUI library, as most of them support text rendering (with line wrapping, styling, etc).
I believe the way Notch does it is he manually draws the characters onto an image and then has a method for drawing the specified characters from that image.
Look into the g.drawImage(Image image, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2, ImageObserver observer) method.
Thanks, I’ve looked into that and now the font will render… just not correctly…
Here is the code I’m using:
http://pastebin.java-gaming.org/54a6b9d54
public static void Render(Graphics2D g, String msg, int x, int y){
msg = msg.toUpperCase();
int length = msg.length();
;
There’s a ; that shouldn’t be there, but I don’t think that’s the problem, will you tell us what’s not correct?
:o you re-read and re-draw the image every single time you call render! Don’t do that! Load the image once and store it as a variable to be reused.
When drawing the letter, your destination x2 should be x+8 not x + (length * 8 ) since that’s making the letter as wide as the entire word length
Also, since your letters at 8x8 pixels, you should be doing (c%29) * 8 and (c/29) * 8
Lastly, you should check if c == -1 so it can skip drawing that non-existant letter. This will probably be needed for spaces so don’t forget to add 8 to x, or better yet, don’t add 8 to x and simply add i * 8 to x when drawing
THIS. Thank you so much, I think that you can tell that I’m relatively new at this. This solved my problems. You, my sir, are awesome.
Glad to help! ;D
EDIT: One thing I didn’t mention, no need to round that last source y2, since you’re already doing int division.