[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] move problems



hi,

K_UP has the value 273 and pygame.key.get_pressed() returns a tuple where the 
n'th value is 1 if the n'th key was pressed.
This should work:

if key[K_UP]:
    .....

> this code is in my main game loop
>
> key = pygame.key.get_pressed() #create a key index
>
>     if K_UP in key: #check if the up arrow is pressed
>         redcar.speed = (0, -2)
>     else:
>         redcar.speed = (0, 0)
>
>     redcar.rect = redcar.rect.move(redcar.speed) #move redcar by speed
>
> but pressing the up arrow doesn't move the sprite.