[英]How do I make text appear letter by letter in a box in Pygame?
So I need a way to make a text box with text that appears letter by letter (like ones you see in Undertale, Earthbound, and many more RPGs).所以我需要一种方法来制作一个文本框,其中包含一个字母一个字母的文本(就像你在 Undertale、Earthbound 和更多 RPG 中看到的那样)。 I was wondering how I could do that in Pygame (I dont have code I just need help with how I would be able to do this)
我想知道如何在 Pygame 中做到这一点(我没有代码,我只需要帮助我如何做到这一点)
You'd probably have to print each letter and do a sleep between each one您可能必须打印每个字母并在每个字母之间进行睡眠
See Typewriter Effect Pygame .参见打字机效果 Pygame 。 The basic idea is that you use a timer event (
pygame.time.set_timer()
) and append the text letter by letter:基本思想是你使用一个定时器事件(
pygame.time.set_timer()
)和 append 一个字母一个字母的文本:
typewriter_event = pygame.USEREVENT+1
pygame.time.set_timer(typewriter_event, 100)
text = 'Hello World'
typewriter_text = ""
while run:
# [...]
for event in pygame.event.get():
if event.type == typewriter_event:
if len(typewriter_text) < len(text):
typewriter_text += text[len(typewriter_text)]
Unfortunately pygame cannot render text with line breaks.不幸的是 pygame 无法呈现带有换行符的文本。 You have to render the test line by line.
您必须逐行渲染测试。 See Rendering text with multiple lines in pygame
请参阅pygame 中的多行渲染文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.