0

I wrote this command to load images in Pygame Python

sun_img = pygame.image.load('img/sun.png')
bg_img = pygame.image.load('img/sky.png')


run= True
while run:

    screen.blit(bg_img, (0, 0))
    screen.blit(sun_img, (100, 100))

But the image wasn't loaded when I ran the program. Also, I didn't get any type of error. Please check if I am doing anything wrong or tell me what to do!!

Spino_PPG
  • 41
  • 4

1 Answers1

2

You have to update the display and to handle the events:

run= True
while run:

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            run = False

    screen.blit(bg_img, (0, 0))
    screen.blit(sun_img, (100, 100))

    pygame.dispaly.flip()

The typical PyGame application loop has to:

You are actually drawing on a Surface object. If you draw on the Surface associated to the PyGame display, this is not immediately visible in the display. The changes become visibel, when the display is updated with either pygame.display.update() or pygame.display.flip().

See pygame.display.flip():

This will update the contents of the entire display.

See pygame.event.get() respectively pygame.event.pump():

For each frame of your game, you will need to make some sort of call to the event queue. This ensures your program can internally interact with the rest of the operating system.

Rabbid76
  • 177,135
  • 25
  • 101
  • 146