Why is the PyGame animation is flickering

The problem is caused by multiple calls to pygame.display.update(). An update of the display at the end of the application loop is sufficient. Multiple calls to pygame.display.update() or pygame.display.flip() cause flickering.

Remove all calls to pygame.display.update() from your code, but call it once at the end of the application loop:

while running:
    screen.fill((225, 0, 0))
    # pygame.display.update() <---- DELETE

    # [...]

    player(playerX, playerY)
    pygame.display.update()

If you update the display after screen.fill(), the display will be shown filled with the background color for a short moment. Then the player is drawn (blit) and the display is shown with the player on top of the background.

Leave a Comment