using Godot; using System; public partial class TestMap : TileMapLayer { /// /// The last cell that was highlighted. Used to avoid unnecessary updates. /// 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; } /// /// Called every frame. /// /// the elapsed time since the previous frame. 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); } } }