I'm trying to add some text effects to my game by making the text "type"
Here, maybe the pseudocode will make it understandable.
String text = "But what I do have are a very particular set of skills, skills I have acquired over a very long career.";
char = characters(text) ///turn string into list/array of letters
i = 0; //initializes i
while (i < text.length) {
print(char.letter[i]) ///print 'i'th letter in list (starting with 1)
TimeUnit.MILLISECONDS.sleep(100) //wait 1/10th of second
i++; //repeat for all letters
}
P.S. comments with triple slashes are things i don't know how to do
解决方案
Simply use for-each loop over chars of input text:
String text = "...";
for(char c : text.toCharArray()) {
System.out.print(c);
Thread.sleep(100);
}
System.out.println();