0

There is a code like this:

keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT]:
    self.image = cycle_left
    self.rect.x -= self.speed
elif keys[pygame.K_RIGHT]:
    self.image = cycle_right
    self.rect.x += self.speed
elif keys[pygame.K_UP]:
    self.image = cycle_up
    self.rect.y -= self.speed
elif keys[pygame.K_DOWN]:
    self.image = cycle_down
    self.rect.y += self.speed
else:
    self.image = cycle_up
    self.rect.y -= self.speed

If you press and hold the left arrow (or any other), the motorcycle will go left until I release the key. And I need to make it so that it was enough to press a key once and the motorcycle drove to the left until another key was pressed. P.S .: The second problem, even if you hold down the key and go to the left, the picture jerks between cycle_up and cycle_left

Nitrolacs
  • 31
  • 4

1 Answers1

0

You can use this kind of structure:

DIRECTION = ""
if keys[pygame.K_LEFT]:
    DIRECTION = "LEFT"
#...
if DIRECTION == "LEFT":
    #do something
Seppeke
  • 143
  • 7