如何阻止 pygame 精灵离开 'tail'

How to stop pygame sprite leaving 'tail'

我的 pygame/python 程序有问题。我正在使用 3.3。正在发生的事情的屏幕截图位于: http://i.imgur.com/Lc0Uftq.png

现在您应该能够看到,当您在刷新之前移动方块时,这意味着您在屏幕上留下了自己的踪迹。目前我有这个:

code to initiate pygame and set background
x=0 #starting cords
y=0
image = pygame.image.load(os.path.join("textures","necromancer.png")) #set image location
running=True
while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.display.quit()
            running=False
            break
        key = pygame.key.get_pressed() #take key user presses to use in below if/elif statements
        dist = 20 #amount sprite will move when one key is pressed
        if key[pygame.K_DOWN]:
            y += dist
        elif key[pygame.K_UP]:
            y -= dist
        elif key[pygame.K_RIGHT]:
            x += dist
        elif key[pygame.K_LEFT]:
            x -= dist
        screen.blit(image, (x, y))
        print(x)
        print(y)
        pygame.display.update()

有什么办法可以阻止这种情况发生吗?

记住最后的位置并在移动后重新绘制它。

当有人按下键时记住位置 old_x = xold_y = y
old_xold_y 上移动重绘位置后。