TileMapLayer tiles to gui textures?

Godot Version

4.6

Question

I’m trying to start on a level editor, but I’ve been getting hung up on how to get tiles from TileMapLayer to the gui. I’m making the buttons instantiated scenes with a script to change a main “currently selected part” variable (just writing it here in case there’s a better way to do it)

My issue is that I want it to automatically make tiles to select from the TileSet it’s given. So it’d have to instantiate a button scene to the GridContainer, then that button would have to update its texture to be whatever tile it is. Repeat for however many tiles are in the given tileset.

Get it from TileSetAtlasSource object which can be obtained by TileSet::get_source()

yeah that worked, i got it functioning with this

var source = tileset.get_source(0)
	for i in range(source.get_tiles_count()):
		var coords = source.get_tile_id(i)
		var atlastex = AtlasTexture.new()
		atlastex.atlas = source.texture
		atlastex.region = source.get_tile_texture_region(coords)
		var holder = PALETTE_BUTTON.instantiate()
		holder.get_node("Control/TileButton").texture_normal = atlastex
		holder.get_node("TileHighlight").modulate.a = 0.0
		holder.get_node("Control/TileButton").pressed.connect(func(): select_tile(coords, holder))
		palette_grid.add_child(holder)

..and select_tile() will set a variable that the drawing function uses via set_cell(). The way this is set up right now only lets you place one specific tile at a time, which is probably not ergonomic. I guess I should go figure out terrains :stuck_out_tongue:

1 Like