Okay I’m sure you’ve seen this playing many a video game. But when you get to a story part or a part where someone is talking the text types it self out… the speed is usuall determined via the Text Speed. How to I get my string outputs to do the same thing. Essentially making it possible to buffer my text and output it letter by letter or such so it looks like its typing or appearing when someone is talking as opposed to BAM its there?
It depends in your game loop.
If you have separated logic and rendering, you need two strings one with all the text, one with the text written, and an int to hold the position.
String message = "This is my very long text that must appear letter by letter";
String screenMessage = ""; //stars empty
int messagePos = 0;
Then in your logic code:
//update the message
screenMessage = screenMessage + message.charAt(messagePos);
messagePos++;
if(messagePos == mesage.length())
//End of message.
And in your render code:
//Draw the message
g.drawString(screenMessage,posX,posY);
This will update your text at the same speed of your refresh rate. You should have to add som delay betwen update in the logic code to make it slower.
Rafael.-
Rock on. This makes much sense!