So I managed to create, import and display a 16x16 TileMap in my PyGame project. I have my asset layer called ground and an Objects layer originally called objects.
Tile software screenshot with my layers
Then I've got this simple code to create my TileMap :
class TiledMap:
def __init__(self, filename):
tm = pytmx.load_pygame(filename, pixelalpha=True)
self.width = tm.width * TILE_SIZE
self.height = tm.height * TILE_SIZE
self.tmxdata = tm
def render(self, surface):
ti = self.tmxdata.get_tile_image_by_gid
for layer in self.tmxdata.visible_layers:
if isinstance(layer, pytmx.TiledTileLayer):
for x, y, gid, in layer:
tile = ti(gid)
if tile:
tile = pg.transform.scale(tile,(TILE_SIZE,TILE_SIZE))
surface.blit(tile, (x * TILE_SIZE,
y * TILE_SIZE))
def make_map(self):
temp_surface = pg.Surface((self.width, self.height), pg.SRCALPHA).convert_alpha()
self.render(temp_surface)
return temp_surface
EDIT: I've forgot to say that my 16x16 map is actually rescaled to a 64x64 (TILE_SIZE) image, but only for the visible layer ground, I want to do it with the objects layer too.
This is working great to scale my "visible layer" which is ground. But when I draw the collisions you can see that the objects are still really small and don't fit my new map resolution :
Game screenshot with in Blue:Player hit box and in Yellow:Colliders
As you can see the hit boxes of the walls I've set in my TileMap are not correctly scaled.
So question is, how to scale the Objects layer of a TileMap with pyTMX ?
Thank you all.