Tileset Strange behaviour Bug or misunderstanding

I just stumbled over this issue on Stackoverflow and thought, if this is an bug/issue I should maybe open it, on the phaser github repo.

The issue seems to be, if I pass multiple tilesets to createBlankLayer and use putTileAt with a gid / Tile-Number that exceeds the max size of possible tiles in one of the tileset images, this generates an error (of course with the gid within the combined total of all tilesets tile-count):

TypeError: Cannot read properties of undefined (reading ‘2’)

I create a code pen, with the SO-Code, so that it throws this Error (in the console): https://codepen.io/akumagamo/pen/ExzgMBP

So my question is, is this I Bug and should I post it on github, or did I misunderstand how this feature should be used. If the later, how could/should the feature be used?

Thanks in advance for the support.

Pass firstgid in addTilesetImage() instead.

Thank you, that worked like a charm. :+1:

You can also set those manually if you rebuild the tileset index afterwards.

tiles1.firstgid = 0;
tiles2.firstgid = tiles1.firstgid + tiles1.total;
tiles3.firstgid = tiles2.firstgid + tiles2.total;
tiles4.firstgid = tiles3.firstgid + tiles3.total;

map.tiles = Phaser.Tilemaps.Parsers.Tiled.BuildTilesetIndex(map);