1

I am writing a game in PyGame. But when I want to load images, the background image is not loading up correctly. Also, no error message is showing up.

The code:

import pygame
from pygame.locals import *


# Images
icon = pygame.image.load("Images/icon.ico")

background = pygame.image.load("Images/sky.png")
sun = pygame.image.load("Images/sun.png")

# Setup
pygame.init()
screen = pygame.display.set_mode((700, 700))
pygame.display.set_caption("Platformer")
pygame.display.set_icon(icon)

# Game loop
running = True

while  running:
    screen.blit(background, (0, 0))
    screen.blit(sun, (100, 100))
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    pygame.display.update()
pygame.quit()

Here's what I got:
link to image

Geeky Quentin
  • 2,469
  • 2
  • 7
  • 28
  • 1
    I literally copied all your code and tested it out with some images with the same name and same type. It is working properly. The issue might be with the images. Can you show the folder containing the images? – Geeky Quentin May 14 '22 at 06:42
  • @GeekyQuentin I don't know if there is something wrong with the folder, but here's a screenshot: [link](https://imgur.com/a/FdALNn1) –  May 14 '22 at 07:16

1 Answers1

1

I think it might be because you did pygame.init() after using pygame.image.load().

Basically it can't load it because it's not initiated yet, but I'm not sure about that.

lemon
  • 14,875
  • 6
  • 18
  • 38
Bup
  • 11
  • 2