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();
博客内容展示了如何用Java编程实现文字逐字显示的打字机效果,通过for-each循环遍历输入字符串的字符并逐个打印,每个字符间加入短暂延迟,模拟打字过程。
2459

被折叠的 条评论
为什么被折叠?



