I'm having troubles to correctly load and blit PNG image with Pygame. Code is actually working, but it display some strange and black "things" around my sprite :
To load tileset, I do:
def TilesRessourceFile(self, filename=None, tileSize=None, tiles=None):
logging.info("Loading ressources from %s", filename)
self._tileSize = tileSize
res = pygame.image.load(filename)
res.convert_alpha()
for tile in tiles:
name, (x, y), alpha = tile.values()
surface = pygame.Surface((tileSize, tileSize))
surface.blit(res, (0, 0), area=(x * tileSize, y * tileSize, (x + 1) * tileSize, (y + 1) * tileSize))
surface.convert_alpha() # set_colorkey(alpha)
self._tiles.update({name: surface})
Then I blit the sprite like this
def _implGameObjectRender(self, screen):
# logging.info("Render map %s", self._mapping)
for i in range(len(self._mapping)):
for j in range(len(self._mapping[i])):
screen.blit(self._mapping[i][j], (j * 128, i * 128))
It's probably not much, but I don't find the solution by myself. I already tried to check :
- how to load PNG with pygame
- transparency with pygame (convert and convert_alpha)
I'm using this tileset : https://www.gamedevmarket.net/asset/2d-hand-painted-town-tileset-6626/
The tileset provide a json file to load with Tiled. Also tried this, and it perfectly works so I guess the problem is on my side
Thanks for helping me !
Python 3.9.1 Pygame 2.0.1 (SDL 2.0.14)