'The Pygame image is not loading up correctly [duplicate]
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:
Solution 1:[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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | lemon |