#How can i add modulate to a specific cell on a tilemaplayer?

1 messages · Page 1 of 1 (latest)

forest mesa
#

This

shut thicket
#

To modify a specific index, you need to create a custom TileMapLayer script and override the _TileDataRuntimeUpdate method. The below C# script should be close and give you an idea. The script is a quick adjustment from a tile offset tweening script that I had, so there may be some errors.

[GlobalClass]
public partial class ModulateTileMapLayer : TileMapLayer
{
    private Dictionary<Vector2I, Color> ModulateColors { get; } = new Dictionary<Vector2I, Color>();

    public override void _Process(double delta)
    {
        base._Process(delta);

        if (ModulateColors.Count > 0)
            NotifyRuntimeTileDataUpdate(); // Could possibly be moved to the SetModulateColor method.
    }

    public override bool _UseTileDataRuntimeUpdate(Vector2I coords)
    {
        return base._UseTileDataRuntimeUpdate(coords)
            || ModulateColors.ContainsKey(coords);
    }

    public override void _TileDataRuntimeUpdate(Vector2I coords, TileData tileData)
    {
        base._TileDataRuntimeUpdate(coords, tileData);

        if (ModulateColors.TryGetValue(coords, out var color))
        {
            tileData.Modulate = color;
        }
    }

    public void SetModulateColor(Vector2I index, Color color)
    {
         ModulateColors[index] = color;
    }
}