[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] key refrence~



black wrote:
> So, I write code like your style but get another response. this is my
> code below :
> 
> while 1 :
>     ev=pygame.key.get_pressed()
>     if ev[pygame.K_LEFT] :
>         posX-=50
>         screen.blit(pic, (posX, posY))
>         pygame.display.update()
>     elif ev[pygame.K_RIGHT]:
>         posX+=50
>         screen.blit(pic, (posX, posY))
>         pygame.display.update()
> 
> as you see I just want to move my picture, 50 pixels left when left key
> is pressed and 50 pixels right when right key is pressed. but it refuse
> to move when testing. anyone could point out where the error is ? thanx~

once per frame in your game you must make at least one call to one of the
pygame event queue functions. otherwise pygame has no good way to process
input from the operating system. the way you are just getting the key
pressed state you will want to add

pygame.event.pump()

to your loop, call it right before key.get_pressed() and you should be ok.

also, see the last email i sent you on this, it had a full working example
attached. it used input events to handle the keypresses, so it was a little
different than key.get_pressed(), but it works just as well, if not a
little better.






____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org