pygame / pygameweb

🎮🕸️ pygame.org website. Python, PostgreSQL, Flask, sqlalchemy, JS.
https://www.pygame.org/
BSD 2-Clause "Simplified" License
120 stars 29 forks source link

Unsupported Image Format #188

Open jcpjcp99 opened 4 months ago

jcpjcp99 commented 4 months ago

Pygame version 2.6; Python version: 3.12.3

Trying to load a PNG file generates the following error:

File "/home/john/Pygame/Platform_Game/game.py", line 20, in get_background image = pygame.image.load(os.path.join('assets', 'Background'), name) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ pygame.error: Unsupported image format

Image attached Blue1

The troublesome line of code in bold below.

`import os import random import math import pygame from os import listdir from os.path import isfile, join

pygame.init()

pygame.display.set_caption('Platform Game')

BG_COLOR = (255, 255, 255) WIDTH, HEIGHT = 1000, 800 FPS = 60 PLAYER_VEL = 5

window = pygame.display.set_mode((WIDTH, HEIGHT))

def getbackground(name): image = pygame.image.load(os.path.join('assets', 'Background'), name) , _, width, height = image.get_rect() tiles = []

for i in range(WIDTH//width +1):
    for j in range(HEIGHT//height +1):
        pos = (i*width, j*height)
        tiles.append(pos)

return tiles, image

def draw(window, background, bg_image): for tile in background: window.blit(bg_image, tile)

pygame.display.update()

def main(window): clock = pygame.time.Clock() background, bg_image = get_background('Blue1.png')

run = True
while run:
    clock.tick(FPS)

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

    draw(window, background, bg_image)

pygame.quit()
quit()

if name == 'main': main(window)`

John