41 lines
1020 B
C#
41 lines
1020 B
C#
using Godot;
|
|
using System;
|
|
|
|
|
|
public partial class TestMap : TileMapLayer
|
|
{
|
|
/// <summary>
|
|
/// The last cell that was highlighted. Used to avoid unnecessary updates.
|
|
/// </summary>
|
|
private Vector2I _lastHighlightCell;
|
|
private readonly Vector2I _highlightTileCoord = new(0, 5);
|
|
private readonly Vector2I _vector2INegOne = new(-1, -1);
|
|
// Called when the node enters the scene tree for the first time.
|
|
public override void _Ready()
|
|
{
|
|
// Initialize the lastHighlightCell to an invalid value.
|
|
_lastHighlightCell = _vector2INegOne;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Called every frame.
|
|
/// </summary>
|
|
/// <param name="delta">the elapsed time since the previous frame.</param>
|
|
public override void _Process(double delta)
|
|
{
|
|
Vector2 mousePos = GetLocalMousePosition();
|
|
Vector2I cell = LocalToMap(mousePos);
|
|
|
|
if (cell != _lastHighlightCell)
|
|
{
|
|
if (_lastHighlightCell != _vector2INegOne)
|
|
{
|
|
EraseCell(_lastHighlightCell);
|
|
}
|
|
_lastHighlightCell = cell;
|
|
SetCell(cell, 0, _highlightTileCoord);
|
|
}
|
|
}
|
|
|
|
}
|