Godot TileMapLayer => TileSet Logic

This commit is contained in:
Torsten 2025-11-05 05:29:51 +01:00
parent 08ed389c8a
commit c674fcd965

View file

@ -0,0 +1,24 @@
```gdscript
func display_layer_data():
# Assume TileMapLayer node is referenced as 'tile_map_layer'
var tile_set = self.tile_set
# Get the number of TileSetSources (sources in tileset)
var source_count = tile_set.get_source_count()
print("Number of sources in TileSet: ", source_count)
# Iterate over all sources in the tileset
for i in range(source_count):
var source_id = tile_set.get_source_id(i) # integer ID of source (atlas source)
# Get the source resource
var source = tile_set.get_source(source_id)
# Check if this source is an Atlas type source
if source is TileSetAtlasSource:
print("Found Atlas Source ID: ", source_id)
print("Atlas Grid Size: ", source.get_atlas_grid_size())
# You can now use this source_id as the valid atlas source ID assigned to the TileMapLayer
```