Tiled Plugin 1.7 – Alpha and Color

The latest version of the Tiled plugin adds per-layer Alpha and Color (Red, Green, and Blue) values, enabling even more flexibility in rendering .tmx files.

Alpha From TMX

The Tiled program supports alpha values on each layer. Setting the alpha on a layer will automatically apply that alpha when the game runs.

Changing Color/Alpha in Code

The latest plugin also adds the ability to change the color/alpha values in code. Since each layer is drawn independently, each layer can be adjusted on its own.

For example, the following code shows how to adjust the alpha and color values of a map with 2 layers.

void CustomInitialize()
{
    var firstLayer = Level1File.MapLayers[0];

    // 1 means to show the color as-is in the TMX
    firstLayer.Red = 1;
    firstLayer.Green = 0;
    firstLayer.Blue = 0;

    var secondLayer = Level1File.MapLayers[1];
    secondLayer.Alpha = .75f;
}

This code will produce the following when the game runs:

The above image and code use the following tilemap:

When adjusting layer color and alpha values, keep in mind:

  • Each layer can be adjusted independently
  • Alpha values in code will overwrite the Opacity value set in Tiled
  • Color values apply a Modulate (also called multiply) effect. For information on how Modulate works, see the Modulate page.
  • Color values of 1 will result in the map being drawn without any modifications. A value of 0 will remove the particular color. In the example above, Green and Blue are set to 0, which is why the map draws red.
  • Values can be greater than 1 to make maps draw with additional brightness