when ever I try to display to render this text 1 by 1 it seems to slow my game down and make everything run slow and for some reason it starts the text as well I want it to end when its finished typing the text VIDEO< as you can see in the video the text keeps playing the game keeps lagging for some reason when ever each of the text is rendered on the screen
def show_text(string):
WHITE = (255, 255, 255)
text = ''
font = pygame.font.Font("Alice.ttf", 30)
for i in range(len(string)):
text += string[i]
text_surface = font.render(text, True, WHITE)
text_rect = text_surface.get_rect()
text_rect.center = (700/2, 800/2)
window.blit(text_surface, text_rect)
pygame.display.update()
pygame.time.wait(100)
display_text_animation('Hello World!')
heres the full code there all rects execept the Alice.tff < text style
import pygame, sys
from pygame.locals import *
WINDOW_WIDTH = 500
WINDOW_HEIGHT = 500
pygame.init()
DISPLAYSURF = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
BLACK = ( 0, 0, 0)
WHITE = (255, 255, 255)
class player:
def __init__(self,x,y,height,width,color):
self.x = x
self.y = y
self.height = height
self.width = width
self.color = color
self.rect = pygame.Rect(x,y,height,width)
def draw(self):
self.rect.topleft = (self.x,self.y)
pygame.draw.rect(DISPLAYSURF,self.color,self.rect)
white = (120,120,120)
player1 = player(150,150,50,50,white)
def display_text_animation(string):
text = ''
for i in range(len(string)):
text += string[i]
font = pygame.font.Font("Alice.ttf", 30)
text_surface = font.render(text, True, white)
text_rect = text_surface.get_rect()
DISPLAYSURF.blit(text_surface, text_rect)
pygame.display.update()
pygame.time.wait(100)
def main():
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
keys = pygame.key.get_pressed()
if keys[pygame.K_d]:
player1.x += 5
if keys[pygame.K_a]:
player1.x -= 5
DISPLAYSURF.fill((0,0,0))
player1.draw()
display_text_animation('Hello World!')
main()