我试图在移动后删除上一张图像。这是我如何移动图像的代码(unit0
def Move(x, y):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
Background.blit(RedInfantry,(-x*64, 0))
if event.key == pygame.K_RIGHT:
Background.blit(RedInfantry,(x*64, 0))
if event.key == pygame.K_UP:
Background.blit(RedInfantry,(0, -y*64))
if event.key == pygame.K_DOWN:
Background.blit(RedInfantry,(0, y*64))
起始位置在左上角,而不是图像所在的位置。此外,一旦移动,我也不知道如何删除该图像。如果我在不同方向上移动了两次,则会创建分开的图像,而不是删除最后一个图像。
如何删除上一张图像?
根据先前的一个问题(Image loading using pygame,您必须更改图像在网格中的位置:
if event.type == pygame.KEYDOWN:
new_x, new_y = x, y
if event.key == pygame.K_LEFT:
new_x -= 1
if event.key == pygame.K_RIGHT:
new_x += 1
if event.key == pygame.K_UP:
new_y -= 1
if event.key == pygame.K_DOWN:
new_x += 1
grid[new_x][new_y] = grid[x][y]
grid[x][y] = None
当然,您必须在每一帧中重新绘制整个场景(网格和图像)。(如Image loading using pygame的答案)