[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
R: [pygame] key pressed problem
It doesn't work 'cause I need that if no keys are pressed, my hero stops
(hero.direction = -1)...
In this way the hero doesn't stop...he runs away...
-----Messaggio originale-----
Da: owner-pygame-users@seul.org [mailto:owner-pygame-users@seul.org] Per
conto di Guillaume Proux
Inviato: venerd́ 25 ottobre 2002 11.01
A: pygame-users@seul.org
Oggetto: Re: [pygame] key pressed problem
Gabriele Farina wrote:
> when I run this script and I press one key, there are no problems;
when
> I press a second key while I'm pressing the first one, the hero moves
in
> the right direction. But when I release one of the two keys the hero
> stops...
>
> why?
what about?
while 1:
#time.sleep(0.05)
for e in pygame.event.get():
if e.type == QUIT:
break
elif e.type == KEYDOWN or e.type == KEYUP :
k = pygame.key.get_pressed()
chiave(hero,k)
else:
hero.direction = -1
When you release a key, you have an event KEYUP. Just process it
normally.
Guillaume
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org