How to handle tile rotation in pytmx?

214 views Asked by At

I am loading a map from Tiled with pytmx, but when i draw the tiles, they aren't rotated like in the editor.

The code i'm using to draw the map is this:

tiled_map = pytmx.util_pygame.load_pygame(f"mymap.tmx")
tile_list = []
tile_group = pygame.sprite.Group()
tile_layer = tiled_map.get_layer_by_name("tiles")
for x, y, image in tile_layer.tiles():
    tile = Tile(x*self.tiled_map.tilewidth, y*self.tiled_map.tileheight, image=image)
    tile_group.add(tile)
    tilelist.append(tile)

#later in the code
for tile in tile_list:
    sur.blit(tile.image, (tile.x, tile.y))

The tiles all get drawn out in the correct place, but they all have the default rotation, even though they are rotated in Tiled: in tiled In pygame

I know this question is similar to How to correctly display rotation object with pytmx?, but it did not help me as my problem is with tiles and not objects.

1

There are 1 answers

0
Andrew On

Why are you using a .tmx file to export the map? save the map as CSV, CSV is more accessible a lot than .tmx .tmx is used to save and load it in Tiled not used in rendering the Map

That is what I use

Map = open("*map file location*", 'r')

Read = csv.reader(Mapv)

for row in Read:
    Tile.append(row)

and put this in the while loop

for y in range(8):
    for x in range(60):
         if Tile[y][x] == '*the_tile_number*':
              Screen.blit(*block_surface*, (x*60,y*60))