if I render the text it all types in one spot and lags the game
13. Thread.sleep(millisPerChar);
Is this called in your main thread? It will stop whatever thread it is called in. If this is called in another thread other than your main thread, I'd be concerned about how you are handling thread lifetime management.
A more common way to do this is for your main game loop to update a clock or timer. You might have something more like this:
void typeWriter(String message, long millisPerChar, ...) {
...
// Record when we are starting the message, and how long it should run.
m_startTime = Simulation.Clock.Now();
if(millisPerChar > 0 ) {
m_millisecondsPerChar = millisPerChar;
} else {
m_millisecondsPerChar = DEFAULT_MILLIS_PER_CHAR;
}
...
}
void update()
{
// Display up to the full length of the message, allowing for skipping
int length = m_message.length;
if(!SkipWasPressed) {
length = Math.min( ((Simulation.Clock.Now()-m_startTime) / m_millisecondsPerChar), length);
DrawString( m_message.substring(0,length), ...
...