[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] keep a key pressed and then move a sprite
Hi,
Try this:
while True:
clock.tick(60) #set on 60 frames per second
for event in pygame.event.get():
if event.type == QUIT:
sys.exit()
key = pygame.key.get_pressed()
if key[K_LEFT]: heroes.move_left()
pygame.display.update(heroes_group.draw(screen))
The PyGame event manager fires events only when a key's state changes (that is, the moment it is pressed or the moment it was released, a single event is fired).
What you want to do is to check the current state of the keyboard. "pygame.key.get_pressed()" does this. The state "key" that it returns can then be checked for the required key.
Ian