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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
| public class VisualNovelState extends BasicGameState{ 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;
private int stateId; private Image background; private Image portrait; private Image nameBox; private Image dialogueBox; private String nameText; private String dialogueText; private UnicodeFont font;
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; }
@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)){ } }
public VisualNovelState(int stateId) throws SlickException{ this.setID(stateId); } } |