This post explained the difference between pygame.display.flip() and pygame.display.update().
However, it didn’t seem to be the case when I tested with the following code:
<code>import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
running = True
img = pygame.image.load('player.png').convert_alpha()
position = [50, 50]
clock = pygame.time.Clock()
while running:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT]:
position[0] +=10
position[1] +=10
window.blit(img, position)
pygame.display.update()
</code>
<code>import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
running = True
img = pygame.image.load('player.png').convert_alpha()
position = [50, 50]
clock = pygame.time.Clock()
while running:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT]:
position[0] +=10
position[1] +=10
window.blit(img, position)
pygame.display.update()
</code>
import pygame
pygame.init()
window = pygame.display.set_mode((500, 500))
running = True
img = pygame.image.load('player.png').convert_alpha()
position = [50, 50]
clock = pygame.time.Clock()
while running:
clock.tick(30)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
keys = pygame.key.get_pressed()
if keys[pygame.K_RIGHT]:
position[0] +=10
position[1] +=10
window.blit(img, position)
pygame.display.update()
pygame.display.update
didn’t ‘update’ the screen at all. It showed a static display (no movement of the image). On the other hand, although pygame.display.flip
showed ‘updated’ display, it left a trail of shadows of the image.
What happened? What did I do wrong? How can I get rid of the shadows?