Skip to content
Advertisement

timer is not displaying text in pygame

so I’m trying to make a 3-sec timer but my code just waits 3 secs then continues to my game I’ve been trying to fix it for a week now but it doesn’t work

def main_menu():

                
            if event.type == py.MOUSEBUTTONDOWN:
                while start_in > 0:
    
                    if start:
                        start_label = start_font.render(str(start_in), 1, (255,255,255))
                        WIN.blit(start_label, (WIDTH/2 - start_label.get_width()/2, HEIGHT/2))
                        
                    start_in -=1
                    
                    py.display.update()

                    time.sleep(1) 

                if start_in == 0:
                        start = True

                    
                    
            if start == True:
                  

                main()
 

Advertisement

Answer

You must handle the events in the innen loop. See pygame.event.get():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement