1

After hitting a and d or left and right key , the sprite will still move without me pressing the key.He just won't stop.How can i fix this?

 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)
Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
user9345251
  • 17
  • 1
  • 3
  • 1
    Please post a [minimal, complete example](https://stackoverflow.com/help/mcve). – skrx Mar 10 '18 at 15:37
  • You probably just have to change `self.movex += x` to `self.movex = x` (and the same for `self.movey`), but I can't say that certainly without seeing the complete code. – skrx Mar 10 '18 at 16:25

0 Answers0