'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). 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)
Solution 1:[1]
See Typewriter Effect Pygame. The basic idea is that you use a timer event (pygame.time.set_timer()) and append the text letter by letter:
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. You have to render the test line by line. See Rendering text with multiple lines in pygame
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rabbid76 |
