我一直在 Pygame 中做一个小项目,但我遇到了一个问题。移动角色时,它似乎会在其身后留下痕迹。
while 1:
movey=0
movex=0
x=0
y=0
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYDOWN:
if event.key == K_w:
movey = -1
elif event.key == K_s:
movey = +1
elif event.key == K_a:
movex = -1
elif event.key == K_d:
movex = +1
if event.type == KEYUP:
if event.key == K_w:
movey = 0
elif event.key == K_s:
movey = 0
elif event.key == K_a:
movex = 0
elif event.key == K_d:
movex = 0
x=x+movex
y=y+movey
functions_for_game.character(char, display, x, y)
pygame.display.flip()
if __name__=='__main__':
main()
functions_for_game.character(char, display, x, y) 包含
def character(char, screen, x, y):
char_main = pygame.image.load(char).convert_alpha()
screen.blit(char_main, (x, y))
pygame.display.update()
'Trail' 我的意思是 这个。