按下a和d或左右键后,精灵仍然会在没有我按下键的情况下移动。他只是不会停止。我该如何解决这个问题?
def control(self, x, y):
'''
control player movement
'''
self.movex += x
self.movey += y
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT or event.key == ord('a'):
player.control(-steps , 0)
if event.key == pygame.K_RIGHT or event.key == ord('d'):
player.control(steps , 0)
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT or event.key == ord('a'):
player.control(0 , 0)
if event.key == pygame.K_RIGHT or event.key == ord('d'):
player.control(0 , 0)