I'm making a game with pygame and I encountered a problem with the following code :
while not self.end: # main game loop
keys = pygame.key.get_pressed()
if keys[K_LEFT]:
adddirection(LEFT)
elif keys[K_RIGHT]:
adddirection(RIGHT)
elif keys[K_UP]:
adddirection(UP)
elif keys[K_DOWN]:
adddirection(DOWN)
When I hold TOP arrow or DOWN arrow, if I press any right or left key, nothing will happen, the elif does not resolves. Why ? Should I do this another way ?
If I replace all the 'elif' by 'if' the opposite happens. If I hold left or right, top and down will never resolves.
I would like to understand that weird mechanic.