Can I add tiles from two layers of a tilemap into a single pattern?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Hamster at Dawn

I have created a tilemap with two layers. The second layer is an overlay that appears on top of the player while the first layer appears underneath the player. This has given me the effect that I was trying to achieve. However, I have certain tiles that I want to always have one part on top and one part underneath.

Is there any way to create a tile that spans two different layers? I tried creating a pattern for this but it doesn’t seem to work with tiles on more than one layer. I don’t want to have to manually place both the corresponding tiles on each layer every time I use that tile.

I suppose I could perhaps add the overlay layer in programmatically, but it would be nicer if there was an interface of some kind to do this.

Any suggestions would be appreciated.

:bust_in_silhouette: Reply From: TruiteMorte

Hi, I’m very intersted for a potential answer to this question as I’m working with patterns combining more than 5 sprites on a single tile. It would be a pleasure to be able to paint them alltogether at once :slight_smile:


:bust_in_silhouette: Reply From: Hamster at Dawn

In the end, I used a script to generate the overlay layer. This works in my case because I always have the same tiles on top of each other, so I put down the base layer of tiles and then add the other layer at runtime. I will include some example code below in case it helps anyone.

var base_layer = 0
var overlay_layer = 1

set_layer_z_index(overlay_layer, 2)

var cells_to_add_overlay_to = get_used_cells_by_id(base_layer, source_id, base_atlas_coords)
for cell in cells_to_add_overlay_to:
	set_cell(overlay_layer, cell, source_id, overlay_atlas_coords, alternative_tile)

This creates a new layer and puts the corresponding overlay on top of each tile that matches base_atlas_coords.