java - How to draw text, char by char in LWJGL/Slick2D -


i want ask know how draw string, char char in interval, example, 0.25sec?

"h" (0.25sec) "e" (0.25sec) "l" (0.25sec) "l" (0.25sec) "o"; 

i use drawtext(x, y, string); draw text.

to nicely in slick, recommend utilizing update() method in game. each update tick, can have variable count how many milliseconds (approximate) have passed delta (how long took update), , tack on letter after determined time amount (the speed @ want add letters).

if want using throughout game, recommend making it's own class, such messagefeed or messagewriter or whatever you'd called.

here quick example wrote:

public class textfieldtest extends basicgamestate{      private int stateid = 0;     string text = "this line of text blah blah blah";     string currenttext = "";     int count = 0;     int index = 0;      public textfieldtest(int state) {         this.stateid = state;     }      public void init(gamecontainer gc, statebasedgame sbg) throws slickexception{      }      public void render(gamecontainer gc, statebasedgame sbg, graphics g) throws slickexception{         g.drawstring(currenttext, 40, 40);     }      public void update(gamecontainer gc, statebasedgame sbg, int delta) throws slickexception{         if(count < 25) {             count+=delta;         } else {             count = 0;             if(index < text.length()) {                 currenttext += text.charat(index++);             }         }     }      public int getid(){         return this.stateid;     } } 

in example use 25 threshold, , once break threshold add new letter shown, start count on again. easier using system time stuff, slick gets delta you. can mess around example how want, , can have variable in place of 25 can change text speed you'd want at.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -