basic cursor

This commit is contained in:
Cat Flynn 2022-12-06 01:28:25 +00:00
parent 4b6d0d9e77
commit 17db704a81
2 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,9 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://textures/icon.png" type="Texture" id=1]
[ext_resource path="res://scripts/GridCursor.cs" type="Script" id=2]
[node name="Grid Cursor" type="Sprite"]
modulate = Color( 0, 1, 1, 0.533333 )
texture = ExtResource( 1 )
script = ExtResource( 2 )

View File

@ -0,0 +1,33 @@
using Godot;
using System;
public class GridCursor : Sprite
{
[Export]
public NodePath Grid { get; set; }
private WorldGrid _grid;
public override void _Ready()
{
_grid = GetNode<WorldGrid>(Grid);
}
public override void _Input(InputEvent @event)
{
base._Input(@event);
if (@event is InputEventMouseMotion mouseMoveEvent)
{
var pos = mouseMoveEvent.Position;
_grid.GetGridPos(pos, out var x, out var y);
var position = new Vector2(x + .5f, y + .5f) * _grid.CellSize;
this.Position = position;
}
else if (@event is InputEventMouseButton mouseButtonEvent)
{
var pos = mouseButtonEvent.Position;
_grid.GetGridPos(pos, out var x, out var y);
GD.Print($"({x}, {y})");
}
}
}