I'm planning on putting a dialogue system into my game, I don't really work with surface so my way of implementing SDL_Ttf is by turning it into a texture, in other words, every paragraph would be shown within the rect, is there a way to make the words appear as if they were being typed?
\$\begingroup\$
\$\endgroup\$
2
-
3\$\begingroup\$ you could use a for loop and modify a string so it shows more of it on each iteration of the loop \$\endgroup\$– saloomi2012Apr 12, 2014 at 3:48
-
4\$\begingroup\$ This is broad. Depending on how your game operates, works and looks like will depend on how dialogue is handled. \$\endgroup\$– Vaughan HiltsApr 12, 2014 at 4:17
Add a comment
|
1 Answer
\$\begingroup\$
\$\endgroup\$
1
What you may wish to do in this case is check the timer when you started
printing the text on the screen and decide on an amount
of time that it will take to print each letter in the paragraph.
Then each frame check the time
and print this portion of the text:
int charsToPrint = (time - started) / amount;
if (amount < originalText.length()){
printedPortion = originalText.substr(0, charsToPrint);
else
//DONE: you may wish to do something else here?
printedPortion = originalText;
You will probably want to play a sound when each when each letter is added. You could also accomplish this with a timer or check if (amount > lastAmount) playSomeSound()...
-
4\$\begingroup\$ To make it more realistic, you can also vary the pauses between "typing" letters and insert longer pauses between words. \$\endgroup\$– MatthiasMay 22, 2014 at 7:11