Chargement des texture dans les sous dossiers

This commit is contained in:
Tipragot 2023-10-26 19:21:24 +02:00
parent 95fa11b1f9
commit 77c7b90806

View file

@ -4,7 +4,7 @@ Définis un plugin permettant d'afficher des choses a l'écran.
from engine import *
from engine.math import Vec2
import pygame, os
import pygame, glob
from engine.plugins.pygame import Display
@ -84,10 +84,12 @@ class TextureManager:
def __init__(self, display: Display) -> None:
self._textures: dict[str, pygame.Surface] = {}
for file in os.listdir("textures"):
self._textures[file] = pygame.image.load(f"textures/{file}").convert(
for file in glob.iglob("textures/**/*.png", recursive=True):
self._textures[file] = pygame.image.load(file).convert_alpha(
display._surface
)
for file in glob.iglob("textures/**/*.jpg", recursive=True):
self._textures[file] = pygame.image.load(file).convert(display._surface)
error_texture = pygame.Surface((256, 256))
error_texture.fill((0, 0, 0))
pygame.draw.rect(error_texture, (255, 0, 255), (0, 0, 128, 128))