Topic was automatically imported from the old Question2Answer platform.
Asked By
Aaron
Old Version
Published before Godot 3 was released.
I want to attach different properties to the tile types in a TileSet. Things like “defence bonus” or “movement penalty”.
I imagine I can create a separate script with a dictionary of “tile data” objects keyed by the tile indices in a TileSet. But I can’t think of a way to populate this dictionary other than by hand, and making sure I fix the index keys should I change the corresponding TileSet significantly.
The only thing i can think of if you’re gonna do it for each individual tile would be to put a script inside of each individual tile and possibly attach them to globals, but if somebody has a better answer then i’d sudgest you do what they say
This is shooting from the hip from what little I do know about tiles.
That said, since you can name individual tiles, there should also be a way to check the name of a certain tile in relation to your character. It would have to be able to check relation of choice if it is possible, due to the difference in relevant tile between a top-down and side scrolling game.
Providing this assumption holds true, You can check the relevant tile’s name and apply your own effects against that.
As already discussed, I use it by giving name to tile:
type_name_iterator
Then I will have “floor _ carpet _ 1”, “wall _ brick _ 4”, etc… Then you have to spit name according to “_” separator to retrieve informations.
This is the only way of doing this easily.
If you want more data like price, walking aptitude, armor, you will need some separate dictionnary.
In my game I have a separate tilemap and tileset for game logical tile.
StartPosition is tile with index = 0
Enemy1StartPosition is tile with index = 1
and so on…
With this code you can find the index and position:
var elements_tilemap = get_node("elements")
var elementscells = elements_tilemap.get_used_cells()
for cell in elementscells:
var cell_tile_id = elements_tilemap.get_cell(cell.x,cell.y)
var tmp_pos = elements_tilemap.map_to_world(cell)
You can add then the enemy scene to the position of Enemy1StartPosition.