So I don't know if it's okay to ask the question here, but I figure someone has to know the answer and this is really the only forums I'm on.
Anyway, I've started learning Python and Pygame programming.
I'm trying to make velocity in Pygame, but for some reason I can't figure out how to use it when a key is held down. the velocity only works when it's pressed and doesn't work until the key is pressed again. here's my script so far:
import pygame, sys
from pygame.locals import *
pygame.init()
screen=pygame.display.set_mode((480,360),0,32)
background=pygame.image.load(bif).convert()
mouse_c=pygame.image.load(mif).convert_alpha()
x,y=0,0
movex, movey= 0,0
while True:
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
sys.exit()
if event.type==KEYDOWN:
if event.key==K_LEFT:
movex=movex-.05
elif event.key==K_RIGHT:
movex=movex+.05
elif event.key==K_UP:
movey=movey-.05
elif event.key==K_DOWN:
movey=movey+.05
x=x+movex
if x>400 or x<0:
movex=movex*-1
y=y+movey
if y>280 or y<0:
movey=movey*-1
movex=movex*.999
movey=movey*.999
screen.blit(background, (0,0) )
screen.blit(mouse_c, (x,y) )
pygame.display.update()
So my question is: How do I get Pygame to recognize a key being held down?
Thanks in advance,
AtomicBawm3
Last edited by AtomicBawm3 (2011-06-09 18:52:38)
Offline