Im trying to display Strings of text in Slick2D using the UnicodeFont (because TrueTypeFont is deprecated).
The class I am working on is shown below. Im guessing that lines 106 and 117 are where the problem lies, but I don’t know how to fix it (Ive never displayed text in Slick2D before). Also, everything else works fine.
public class VisualNovelState extends BasicGameState{
//CONSTANTS================================================================
//Note: Most if not all of these constants are temporary for testing purposes.
public static final String BACKGROUND = [FILEPATH];
public static final String PORTRAIT = [FILEPATH];
public static final String NAMEBOX = [FILEPATH];
public static final String DIALOGUEBOX = [FILEPATH];
public static final String TESTSTRING = "Text display test. ";
public static final String FONT = "Arial";
public static final int STYLE = java.awt.Font.PLAIN;
public static final int SIZE = 60;
//ATTRIBUTES===============================================================
/** The id of this GameState. */
private int stateId;
/** The background Image. */
private Image background;
/** The character portrait Image. */
private Image portrait;
/** The Image which contains the nameText on the screen. */
private Image nameBox;
/** The Image which contains the dialogueText on the screen. */
private Image dialogueBox;
/** The name of the current speaker. */
private String nameText;
/** The current line of dialogue. */
private String dialogueText;
/** */
private UnicodeFont font;
//ATTRIBUTE SETTER AND GETTER METHODS======================================
public void setID(int stateId){
this.stateId = stateId;
}
@Override
public int getID() {
return stateId;
}
public void setBackground(Image background){
this.background = background;
}
public Image getBackground(){
return background;
}
public void setPortrait(Image portrait){
this.portrait = portrait;
}
public Image getPortrait(){
return portrait;
}
public void setNameBox(Image nameBox){
this.nameBox = nameBox;
}
public Image getNameBox(){
return nameBox;
}
public void setDialogueBox(Image dialogueBox){
this.dialogueBox = dialogueBox;
}
public Image getDialogueBox(){
return dialogueBox;
}
public void setNameText(String nameText){
this.nameText = nameText;
}
public String getNameText(){
return nameText;
}
public void setDialogueText(String dialogueText){
this.dialogueText = dialogueText;
}
public String getDialogueText(){
return dialogueText;
}
public void setFont(UnicodeFont font){
this.font = font;
}
public UnicodeFont getFont(){
return font;
}
//PRIMARY METHODS==========================================================
@Override
public void init(GameContainer container, StateBasedGame game) throws
SlickException {
this.setBackground(new Image(BACKGROUND));
this.setPortrait(new Image(PORTRAIT));
this.setNameBox(new Image(NAMEBOX));
this.setDialogueBox(new Image(DIALOGUEBOX));
this.setFont(new UnicodeFont(new java.awt.Font(FONT, STYLE, SIZE)));
this.setDialogueText(TESTSTRING);
}
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
this.getBackground().draw(0,0);
this.getPortrait().draw(0,0);
this.getNameBox().draw(0,0);
this.getDialogueBox().draw(0,0);
this.getFont().drawString(1, 450, this.getDialogueText());
}
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
Input input = container.getInput();
if(input.isMouseButtonDown(Input.MOUSE_LEFT_BUTTON)){
}
}
//CONSTRUCTORS=============================================================
public VisualNovelState(int stateId) throws SlickException{
this.setID(stateId);
}
}