Screen only updates when I check for user input pygame

后端 未结 2 1011
余生分开走
余生分开走 2021-01-25 13:04

I\'m using pygame and updating to the screen every loop of the main loop. What I don\'t understand is nothing will update until I add a for loop looking for events, then suddenl

2条回答
  •  情深已故
    2021-01-25 13:33

    No idea why it doesn't work on your end, however when I run

     def run():
        width = 500
        height = 500
        pygame.init()
        font = pygame.font.Font(None, 72)
        screen = pygame.display.set_mode((width, height))
    
        before_two = True
        while before_two:
    
            # Blit the time to the window.
            # Update Screen.
            current_time = datetime.datetime.now()
            text = font.render(f'{current_time.hour} : {current_time.minute} :      {current_time.second}', True, (0, 0, 0))
            blit_center = (
                width // 2 - (text.get_width() // 2),
                height // 2 - (text.get_height() // 2)
            )
            screen.fill((255, 255, 255))
            screen.blit(text, blit_center)
            pygame.display.flip()
    
    
    
    
    run()
    

    Everything works fine update wise. The clock ticks every second so it may be something with your version of python or pygame. Try updating them both. Alternately it could be a problem with how you get pass pygame the dimensions of the window with the run(self) and self._dimensions. Trying using static dimensions like I did above and see if that works on your end. Sadly without more code to see how you call run() its difficult to fully debug whats wrong.

提交回复
热议问题