Summary:
Working with StateBasedGame attempting to implement a simple AngelCodeFont in a BasicGameState via Slick’s AngelCodeFont library and render text to the canvas.
I followed this to the tee: http://www.java-gaming.org/topics/drawing-text-using-slick-2d-library/26944/msg/239187/view.html#msg239187 which produced two outputs, a .fnt file and a .png file.
EDIT: This source is a functioning implementation
public class PlayState extends BasicGameState {
public static Image img;
public static AngelCodeFont font;
public void init(GameContainer gc, StateBasedGame sbg) throws SlickException {
img = new Image("/res/misc/fonts/arial_0.png", false, Image.FILTER_NEAREST);
font = new AngelCodeFont("/res/misc/fonts/arial.fnt", img);
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g) throws SlickException {
font.drawString(500, 500, "meow");
}
}
Console Warning:
Tue Aug 26 21:34:50 EDT 2014 WARN:class org.newdawn.slick.opengl.PNGImageData failed to read the data
java.io.IOException: Only RGB formatted images are supported by the PNGLoader
…
IOException thrown in PNGImageData#loadImage()
PNGDecoder decoder = new PNGDecoder(fis);
if (!decoder.isRGB()) {
throw new IOException("Only RGB formatted images are supported by the PNGLoader");
Two things:
-
I have successfully opened the .png file and re-saved it as a .bmp which has removed this warning - yet it seems as though I’m doing something wrong since I haven’t been able to find anyone else with this issue.
-
The font.drawString() call is rendering the white text to the canvas AND the black background as you would see in the .png file - aka not rendering with transparency (not sure if this is supposed to be automatic or if I’m missing some function call since this was not mentioned in the above post I linked).