Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Slick2D Trying to display text in UnicodeFont  (Read 2097 times)
0 Members and 1 Guest are viewing this topic.
Offline Indignation211

Senior Newbie





« Posted 2012-03-03 22:54:35 »

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{
    //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);
    }
}
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 74
Projects: 15


★★★★★


« Reply #1 - Posted 2012-03-03 23:05:51 »

UnicodeFont has an odd property in that you need to call something like
1  
yourUnicodeFont.loadGlyphs();
in your update method every frame.
Offline Indignation211

Senior Newbie





« Reply #2 - Posted 2012-03-03 23:12:27 »

ok i added that and now I get an exception:
java.lang.IllegalStateException: The UnicodeFont must have at least one effect before any glyphs can be loaded.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline PaidGEEK

Senior Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« Reply #3 - Posted 2012-03-03 23:19:26 »

add maybe a simple color effect:
1  
myFont.getEffects().add(new ColorEffect(java.awt.Color.white));

Improvisational programmer.
Offline Indignation211

Senior Newbie





« Reply #4 - Posted 2012-03-03 23:26:53 »

Thanks to kappa and PaidGEEK. Its working now.
Offline Cero
« Reply #5 - Posted 2012-03-03 23:33:53 »

btw UnicodeFont is kinda bad, and on top of that has crazy memory leaks
just use AngelCodeFont with uses images
which is also the standard for most games, to make a "spritesheet" with characters on them
on the slick website there are also angelcodefont creators. I use and enjoy "BMFont - Bitmap Font Tool"
there are also other upsides to this like outlining which is easy; and its faster.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (34 views)
2014-07-18 06:55:21

Zero Volt (30 views)
2014-07-17 23:47:54

danieldean (25 views)
2014-07-17 23:41:23

MustardPeter (27 views)
2014-07-16 23:30:00

Cero (42 views)
2014-07-16 00:42:17

Riven (44 views)
2014-07-14 18:02:53

OpenGLShaders (33 views)
2014-07-14 16:23:47

Riven (34 views)
2014-07-14 11:51:35

quew8 (30 views)
2014-07-13 13:57:52

SHC (66 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!