0
votes

I have a program where you have a object and need it to move around asteoids. But in the while loop when i press the arrow keys nothing outputs or works for that key.

gameLoop = True
while gameLoop:

    for event in pygame.event.get():
        if (event.type==pygame.QUIT):
            gameLoop=False

        if (event.type==pygame.KEYDOWN):

            if (event.type==pygame.K_LEFT):
                direc1 = -5
1

1 Answers

0
votes

The event type won't ever be the keyname, you have to check event.key after testing for a keypress.

if (event.type==pygame.KEYDOWN):
    if (event.key == pygame.K_LEFT):
            direc1 = -5