using Godot;
///
/// 测试地图层
///
public partial class TestMap : TileMapLayer {
private readonly Vector2I _highlightTileCoord = new(0, 5);
private readonly Vector2I _vector2INegOne = new(-1, -1);
///
/// 上一次高亮的单元格。用于避免不必要的更新。
///
private Vector2I _lastHighlightCell;
// Called when the node enters the scene tree for the first time.
///
/// 场景加载完成时调用
///
public override void _Ready() {
// 初始化最后高亮单元格为无效值。
_lastHighlightCell = _vector2INegOne;
}
///
/// 每帧更新。
///
/// 距离上一帧的时间间隔。
public override void _Process(double delta) {
var mousePos = GetLocalMousePosition();
var cell = LocalToMap(mousePos);
if (cell != _lastHighlightCell) {
if (_lastHighlightCell != _vector2INegOne) EraseCell(_lastHighlightCell);
_lastHighlightCell = cell;
SetCell(cell, 0, _highlightTileCoord);
}
}
}