I am having difficulties setting a background image for my Pygame window. I’ve looked for other sources, but it seems I cannot find anything helpful or useful.
I am currently aiming to make a 2D Platformer, but I want to start with the background first.
Here is my code:
import pygame, sys
from pygame.locals import QUIT
DISPLAYSURF = pygame.display.set_mode((500, 500))
background = pygame.load.image("GRID.jpg")
background = pygame.transform.scale("GRID.jpg",(500,500))
# caption and icon
icon = pygame.image.load("char.png")
# Displays it?
runing = True
for event in pygame.event.get():
if event.type == QUIT:
runing = False
I keep getting:
Could someone please help me?
I don’t know what is wrong.
The first argument for pygame.transform.scale should be a pygame.Surface, not a string.
The function you used earlier, pygame.load.image, returns a pygame.Surface instance, hence you can rewrite your code like this:
I really recommend looking at the docs in the future, it will tell you exactly what type goes there. It will tell you it takes surface instead of string. And even if it did take string, it would be a waste to load it every time.