Skip to content Skip to sidebar Skip to footer

Pygame Keys Only Running Once

def walk(): x = 0 y = 0 dist = 5 frame = 0 while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame

Solution 1:

You have to dedent the line key = pygame.key.get_pressed(): and the two lines below. They are executed only once per event in the event queue because they are in the event loop (for event in pygame.event.get():), but they should be executed in the while loop every frame.

def walk():
    x = 0
    y = 0
    dist = 5
    frame = 0
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        key = pygame.key.get_pressed()
        if key[pygame.K_UP]:
            x = x - 5

Post a Comment for "Pygame Keys Only Running Once"