Reputation: 264
while done == False:
for event in py.event.get():
if event.type == py.QUIT:
done = True
elif event.type == KEYDOWN:
if event.key == K_UP:
player_y += 1
this is my code and my debugger keeps saying that KEYDOWN is not defined. Help please
Upvotes: 1
Views: 209
Reputation: 64
Include this in your code or it wont work
while done == False:
for event in py.event.get():
if event.type == py.QUIT:
done = True
if event.type == py.KEYDOWN:
if event.key == py.K_UP:
player_y += 1
Upvotes: -1
Reputation: 2672
the full call is pygame.KEYDOWN
etc
instead of manually typing out the ones that you need just add this below your import pygame
line from pygame.locals import *
this should work for all the keys you need.
Upvotes: 2
Reputation: 54212
include this on the top of your code:
from pygame import KEYDOWN, K_UP
Add more keys such as K_LEFT, K_RIGHT, K_UP, K_DOWN, K_e
if you like
Upvotes: 4