I'm doing tests on pygame and created a "character" that moves, however it creates a ghost effect on the screen. I would like to know how to solve it.
(Thislandiswhatthecharacterwouldbe)
TheghosteffectthatIamreferringtoisthatwhenyoumove,thecharacter"walks", however it may create a "copy" of it (as shown in the image)
The code I'm going to put from the moving part:
class playerA(pygame.sprite.Sprite):
velocidade = 20
def __init__(self):
pygame.sprite.Sprite.__init__(self)
self.ImagemPlayer = pygame.image.load("dirt.png")
self.rect = self.ImagemPlayer.get_rect()
self.rect.centerx = largura / 2
self.rect.centery = altura - 60
def colocar(self,sup):
sup.blit(self.ImagemPlayer, self.rect)
def main():
while sair != True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sair = True
if(event.type == pygame.KEYDOWN):
if event.key == pygame.K_LEFT :
player.rect.left -= player.velocidade
elif event.key == pygame.K_RIGHT :
player.rect.right += player.velocidade
elif event.key == pygame.K_UP :
player.rect.top -= player.velocidade
elif event.key == pygame.K_DOWN :
player.rect.top += player.velocidade