How to Blend Two Layers of a Tile Map using a Alpha Layer?

Hello! I’m trying to blend two layers of a Tile Map based on where the alpha_layer has tiles.

This is my Tile Source setup. It has 3 textures 512x512 merged together. Each tile is 512x512.:

My Tile Map consists of three layers.

  1. “alpha_layer” which is the layer for the alpha tiles. and it exists on 1.0.
  2. “top_layer” which is for the tiles that are above and need to take the place of white in the alpha tiles.
  3. “bottom_layer” which is for the tiles below and need to take the place of black in the alpha tiles.

Tile Map with all layers enabled:

The three layers are shown separately with images as:
bottom_layer:

top_layer:

alpha_layer:

My goal is to blend the top_layer and bottom_layer using the alpha_layer as a mask. Specifically, I want the white areas in the alpha_layer to reveal the top_layer, and the black areas to reveal the bottom_layer.

Any guidance on how to achieve this effect in Defold would be greatly appreciated. Thank you!