0

I was trying to make a Pygame game, and when I went to the player movement, the player duplicates.

Here is the code:

#import libraries
import pygame
import sys

#variables
width = 850
height = 850
player_movement = 425

pygame.init()
screen = pygame.display.set_mode((width, height))
clock = pygame.time.Clock()

pygame.display.set_caption("Prokect!")

player = pygame.transform.scale2x(pygame.image.load("player.png"))

#main loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_UP:
                player_movement -= 5
            if event.key == pygame.K_DOWN:
                player_movement += 5

                
    screen.blit(player, (10, player_movement))
    pygame.display.update()
    clock.tick(60)

The question is, why does the player duplicate when the sprite (player) is moving?

2 Answers2

1

Clear the screen by filling the screen with a colour.

screen.fill(#Your chosen colour)
Phippsy
  • 62
  • 7
1

Clear the screen with screen.fill(color) and then redraw all images (like the player with new position) that should be visible.
color can be a tuple or list with 3 or 4 elements or a pygame.Color object.