I always getting gid == 1 for first element in maps, even with same tileset. Saved file "example.tmx" have value encoded with CVS. I open file with txt editor and it's look like this:
<data encoding="csv">
24,24,19,24,24,22,19,23,18,23,2
...
This is great. First element is 24'th tile. But when I load map with pytmx, and I try to get x, y, gid it's different.
ti = self.tmxdata.get_tile_image_by_gid
for layer in self.tmxdata.visible_layers:
#print(layer.name)
if layer.name == "layer1":
for x, y, gid in layer:
print(x, y, gid, self.id)
tile = ti(gid)
#print(self.tmxdata.get_tileset_from_gid(gid))
#print(tile)
if tile:
surface.blit(tile, (x * self.tmxdata.tilewidth + (y&1) * self.tmxdata.tilewidth / 2, y * self.tmxdata.tileheight / TILESIZE[0] * TILESIZE[1]))
self.id += 1
Printed values is (first == x, second == y, third == gid, last == id):
0 0 1 0
1 0 1 1
2 0 1 2 ...
And it's for all maps, the first gid is always "1" but it's discribe different tile in different map.
With ti(gid) / get_tile_image_by_gid it's getting correct image. But I want use gid number for other thinks like:
if gid == 1:
self.grass_group.append(...)
else:
self.other_group.append(...)
Ok, I solved it.
In pytmx "register_gid" doesn't work properly for me. I needed to make list like this:
And then when I go through each element in layer, I can get it from this list.