Reputation:
I am coding a game in fonts and I encountered a problem. I have no idea how to use fonts even though I tried everything. Can you also please explain what is a glyph? And where to get .fnt files if that is needed?
Upvotes: 2
Views: 9237
Reputation: 989
Font font = new Font('Verdana', Font.BOLD, 32);
TrueTypeFont ttf = new TrueTypeFont(font, true);
In your update method:
ttf.drawString(32.0f, 32.0f, "Your words here", Color.green);
Upvotes: 2
Reputation: 33954
A lot of that stuff is either no longer used, or just not necessary anymore. Basically all you need is a Graphics instance, and to use something like the drawString method. You can also use setFont on the Graphics object to set the font you want to use for rendering.
You can get a Graphics instance from your GameContainer, and then just render to it. If you want to see an example, the render
method of this file in my project on github has some lines in it that render debug information to the screen (fps, memory usage, etc.). The relevant part of the code is:
if (ConfigValues.renderSystemInfo) {
g.setColor(new Color(50, 50, 50, 180));
g.fillRect(0, 0, 300, 70);
g.setColor(Color.white);
g.drawString("MEM total(used): " + (Runtime.getRuntime().totalMemory()/1000000) + "(" + ((Runtime.getRuntime().totalMemory()-Runtime.getRuntime().freeMemory())/1000000) + ") MB", 10, 25);
g.drawString("Ped. history size: " + (peds.size()*peds.get(0).getMovementHistory().size()) + " nodes", 10, 40);
}
Just for reference, a glyph, at least conceptually, is just the visual representation of a character in a font. So, the way that the letter a
looks in a given font, for example, is that font's glyph for that letter. There's a different glyph for upper and lowercase (a
or A
), which is what makes the upper and lowercase letters appear different in fonts.
Upvotes: 3