Pygame single push event

Posted by Miller92Time on Stack Overflow See other posts from Stack Overflow or by Miller92Time
Published on 2013-10-21T21:50:53Z Indexed on 2013/10/21 21:53 UTC
Read the original article Hit count: 148

Filed under:
|

in Pygame i am trying to translate an image by 10% in each direction using each arrow key. right now the code i am using moves the image as long as the key is pushed down, what I want is for it to move only once regardless if the key is still pushed down or not.

if event.type == KEYDOWN:
    if (event.key == K_RIGHT):
        DISPLAYSURF.fill((255,255,255)) #Clears the screen
        translation_x(100)
        draw(1)
    if (event.key == K_LEFT):
        DISPLAYSURF.fill((255,255,255)) #Clears the screen
        translation_x(-100)
        draw(2)
    if (event.key == K_UP):
        DISPLAYSURF.fill((255,255,255)) #Clears the screen
        translation_y(100)
        draw(3)
    if (event.key == K_DOWN):
        DISPLAYSURF.fill((255,255,255)) #Clears the screen
        translation_y(-100)
        draw(4)

is there a simpler way of implementing this besides using time.sleep

© Stack Overflow or respective owner

Related posts about python

Related posts about pygame