Reputation: 43
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)
Upvotes: 1
Views: 312
Reputation: 210968
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
Upvotes: 1