Skip to content Skip to sidebar Skip to footer

How Do I Blit An Image On A Keypressed Event In Pygame

I'm trying to blit an image to the screen when the event K_SPACE is triggered. However, when I press space nothing happens. I've tried moving where the screen is updated or flipped

Solution 1:

Your image is being displayed, but only 1 time, and then it is washed away by the background. Slow down your loop using clock.tick() and see if it is being displayed.

Solution 2:

Since you have spacePressed, use that to draw the bullet like this:

if spacePressed[K_SPACE]:
    screen.blit(bullet, (bulletx, bullety))

You can use spacePressed for any key as well.

Post a Comment for "How Do I Blit An Image On A Keypressed Event In Pygame"