+2 votes

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.

in Engine by (291 points)

5 Answers

0 votes
Best answer

I think you should go with your original idea, but use tile names instead of indices, and TileMap::get_tileset() and TileSet::tile_get_name.

by (1,608 points)
selected by
0 votes

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

by (483 points)
+1 vote

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.

by (225 points)
0 votes

As already discussed, I use it by giving name to tile:

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.

by (98 points)
+1 vote

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.

by (699 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.