How to use doors in Tiled?

Hi, what’s the best way to include doors in a map (i.e. any interactive element)?

I was hoping to make them a tile instance with a custom property like locked or key_number, but tiles can’t have custom properties :frowning:

So then I have to specify each door as an object in an object layer - and somehow figure out in Phaser how to map that pixel-specific location to the closest tile location, put a door there, and link it to code to animate it for opening and closing. And also then I can’t see the doors in the map builder. I can’t really think of a decent way without tiles having custom data.

You can place the tile graphic itself as an object (using the “Insert Tile” tool). That way you can put custom properties on it and you can see the door in the editor.

1 Like

Oh, this is great, thank you. I don’t know how I missed this in the docs.
Is there any reason not to use object layers for everything, and disregard tile layers entirely?

This is mainly a performance consideration. On a tile layer, each tile only takes 32 bits (in the file format, a bit more while in memory because the tile pointer is resolved), because its location is defined by its index in the tiles array. In contrast each object stores its location and a bunch of other properties, so objects are more heavy-weight. It is also trivial to determine which tiles should be drawn and in which order, whereas freely placed objects may need more complex data structures and sorting.

Still, with today’s hardware there is indeed often no reason to resort to tile layers, and some people create their levels entirely using objects.

From an authoring standpoint, tile layers offer some advantages as well. Because the editor can assume tiles are confined to the grid, it can offer tools like a bucket fill, Terrains, etc. With objects, these tools either don’t make sense or are ambiguous in the general case.

Many of the authoring automation tools Tiled provides only make sense for and work with tile layers. So, while in the end, it might not make a huge* difference whether you use objects or tiles, for authoring, using tiles for those tasks where they’re appropriate can save you a lot of work.

* The difference can be large enough to be noticeable even on modern hardware, depending on the assumptions the engine makes about tiles versus objects. If the engine treats all objects as dynamic even if they’re not (a fairly reasonable assumption if the engine supports tilemaps and other structures to handle static visuals), it’ll be rebuilding the sprite batch(es) and sending them to the GPU far more than it would need to, in addition to possibly running (fruitless) update logic on them. This can quickly add up to noticeable framerate dips and high CPU/GPU usage.