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

Re: [pygame] Keyboard handling



Hello!

To start this off: I'm Martin Sandin. I've been reading this list a (short) while
and I'm just starting up a small Gravity Force esque game in pygame. Nice
experience thus far, has given me very few problems.
(And I'm on the lookout for gfx help). That should be sufficient as an intro
of me to this list :-)

> Hey all, I'm writing a breakout clone in PyGame, and I'm trying
> to implement acceleration for my paddle. I have a Paddle.Move()
> function that continuously adds accel_rate to self.cur_accel, and then
> moves the paddle self.cur_accel to the left or right. The problem is,
> I want the cur_accel to be set back to 0 when the player lets go
> of the key.. I couldn't find anything on 'key release' events, and
> having a 'timeout' period for the key event seems nasty. Any suggestions?
> 

Yupz. Look at aliens.py in the examples directory. It uses a function called
pygame.key.get_pressed(). Brings back a "map" of all key states. Check
this each time through you main game loop and you should be able to
detect key releases as well as key presses. aliens.py does a decent job of
demonstrating how it's handled. Good luck!

-
Martin Sandin
come.to/vague
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org