I am a beginner with pygame. Trying to get KEYDOWN to work in a function.
For some reason it will not register. If I tap space very quickly a bunch of times it will randomly fire and print as it should. However 9 out of 10 times nothing happens. Any ideas?
class Player(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
player_walk_1 = pygame.image.load('graphics/player/player_walk_1.png').convert_alpha()
player_walk_2 = pygame.image.load('graphics/player/player_walk_2.png').convert_alpha()
self.player_walk = [player_walk_1,player_walk_2]
self.player_index = 0
self.player_jump = pygame.image.load('graphics/player/jump.png').convert_alpha()
self.image = self.player_walk[self.player_index]
self.rect = self.image.get_rect(midbottom = (80,300))
def player_input(self):
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
print("it works!")
Hoping to get "it works" to print when I hit space.