Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsupported Image Format #188

Open
jcpjcp99 opened this issue Jul 2, 2024 · 0 comments
Open

Unsupported Image Format #188

jcpjcp99 opened this issue Jul 2, 2024 · 0 comments

Comments

@jcpjcp99
Copy link

jcpjcp99 commented Jul 2, 2024

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 get_background(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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant