0

So, I've done a loop while a key is pressed but if I try stop it when a key is released

pressed_d = False
while True:
    if terrenox < -1920: terrenox = 0
    for event in pygame.event.get():
        if event.type == pygame.KEYDOWN and event.key == pygame.K_d:
            pressed_d = True
    for event in pygame.event.get():
        if event.type == pygame.KEYUP and event.key == pygame.K_d:
            pressed_d = False
    for event in pygame.event.get():
        if (event.type == pygame.KEYDOWN
             and event.key == pygame.K_a):
            terrenox += VEL_AVANZ
    if pressed_d == True:
         terrenox -= VEL_AVANZ

P.S. Terreno is the ground

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • Call `pygame.event.get()` only once. See [Faster version of 'pygame.event.get()'. Why are events being missed and why are the events delayed?](https://stackoverflow.com/questions/58086113/faster-version-of-pygame-event-get-why-are-events-being-missed-and-why-are) – Rabbid76 Feb 27 '23 at 19:46

0 Answers0