A simple problem, but i am new to Python/Pygame. I want to blit an image (old.png) and then have that image be replaced by another image (new.png) upon a keypress (spacebar): sequential presentation. Currently, the old.png remains on the surface, with new.png ending up on top of it.
Here is my code:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.blit(old, (display_width/2, display_height/2))
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
screen.blit(new, (display_width/2, display_height/2))
pygame.display.flip()
clock.tick(30)
You could for example make a variable:
picture = "old"
, and when spacebar is pressed you could do something like:So everytime spacebar is pressed the picture switches
You can keep images on list and use index
current_image
to select image to display. This way you can have more than 2 images.--
BTW: you can use
and then you can use
instead of
in
but if you want to center image correctly you need image rect