People are having a lot of problems loading custom fonts into Slick2D to draw strings with the graphics tool, so here is how I did it.
Asked
Active
Viewed 658 times
1 Answers
2
- First go in your class where you want to use the font.
Declare these variables under the part where your class starts, like so:
public class Easy extends BasicGameState{ //Fonts java.awt.Font UIFont1; org.newdawn.slick.UnicodeFont uniFont;
Since TrueTypeFont loading has many problems, we can use UnicodeFont to load the .ttf fonts(it's exactly the same thing).
Place this in your
init{ ... }
and replace the properties to your liking:try{ UIFont1 = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, org.newdawn.slick.util.ResourceLoader.getResourceAsStream("res/fonts/yourFontFile.ttf")); UIFont1 = UIFont1.deriveFont(java.awt.Font.PLAIN, 16.f); //You can change "PLAIN" to "BOLD" or "ITALIC"... and 16.f is the size of your font uniFont = new org.newdawn.slick.UnicodeFont(UIFont1); uniFont.addAsciiGlyphs(); uniFont.getEffects().add(new ColorEffect(java.awt.Color.white)); //You can change your color here, but you can also change it in the render{ ... } uniFont.addAsciiGlyphs(); uniFont.loadGlyphs(); }catch(Exception e){ e.printStackTrace(); }
- Finally, in your
render{ ... }
, place this in ituniFont.drawString(x, y, "What you want to write here", Color.ChooseYourColorHere)
You can of course change the default names I put for the variables. Keep in mind that I am not the author of all this, I just want to clearly show you how to do it since all the sources I have used either haven't finished, or were just suggestions.

Plumetone
- 101
- 1
- 9