Any way to add metadata to tiles in the tilemap editor?

I was wondering if there’s any way to add additional properties to specific tiles in the tilemap editor. For instance, I may want to create a “portal” object but I would like to add metadata which allows me to specify the destination of the portal (as there may be many in a collection.) I know I can do this via the script but then I have to locate each portal by their coordinates and if I decide to move the portal I have to change the logic. Any ideas/suggestions for how to solve this type of design concern?

No, there is no way to natively assign properties to specific tiles. However, it’s an easy feature to implement yourself. I did this with the my Defold Grid Engine asset:

dge.extra = {}

function dge.get_extra(gx, gy)
	return dge.extra[gx .. gy]
end

function dge.set_extra(extra, gx, gy)
	dge.extra[gx .. gy] = extra
end

function dge.clear_extra()
	dge.extra = {}
end

This allows the user to insert arbitrary data (i.e. a custom table) into any grid position (in this case, grid position is equivalent to tile position.) The user is then able to retrieve the data by specifying the tile coordinates.

Use case of storing “warp” data into tiles, similar to your portals:

location_data.extra = {
	[h_str.location_piglet_hamlet] = {
		{ extra = { id = 3, to_location = h_str.location_cider_path, to_id = 2 }, gx = 1, gy = 12 },
		{ extra = { id = 4, to_location = h_str.location_cider_path, to_id = 1 }, gx = 1, gy = 11 }
	}
}

When the player steps on tile [1, 12] or [1, 11], the extra table from the currently loaded tilemap (in this case location_piglet_hamlet) is retrieved and the warp functionality is called.

2 Likes

I like this method a lot. In a similar case i would have likely just added a trigger collision game object or similar and wasted space with overly specific 1-call function code.

I’ve never had to get THAT specific with tiles before. Closest I’ve ever gotten would be properties based on tile type (ex: tile image 1-4 = passable, tiles 5-24 = solid, tiles 25-32 = slope right, etc)

1 Like

I’d look into using Tiled. It can export to Defold .tilemap format and you can export additional data to for instance json or Lua format.

2 Likes