I'm working on a game where pressing space does something, but a lot of the time, the space key is not registered. I have a main
function and I run a while loop where at the end, I have this:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
(do this)
if event.type == pygame.QUIT:
pygame.quit()
quit()
break
else:
pass
(Before this, I have a few hundred lines of code)
But I find that a lot of the time, nothing happens when I press space and it takes a lot of tries (usually 7-10) before the game responds to the spacebar. I have tried removing time.sleep(0.05)
after pygame.display.update
which has helped a bit. I have also tried making this for loop run more often through my while loop, but it still takes many tries before the game responds to the keypress. What am I doing wrong?