36 lines
937 B
C#
36 lines
937 B
C#
|
using Godot;
|
||
|
|
||
|
namespace AceField.Scripts.Effects;
|
||
|
|
||
|
public partial class OffScreenMarker : Node2D
|
||
|
{
|
||
|
public override void _Process(double delta)
|
||
|
{
|
||
|
var canvas = GetCanvasTransform();
|
||
|
var topLeft = -canvas.Origin / canvas.Scale;
|
||
|
var size = GetViewportRect().Size / canvas.Scale;
|
||
|
SetMarkerPosition(new Rect2(topLeft, size));
|
||
|
SetMarkerRotation();
|
||
|
}
|
||
|
|
||
|
private void SetMarkerPosition(Rect2 bounds)
|
||
|
{
|
||
|
var sprite = GetNode<Sprite2D>("Sprite2D");
|
||
|
sprite.GlobalPosition = new Vector2(
|
||
|
Mathf.Clamp(GlobalPosition.X, bounds.Position.X, bounds.End.X),
|
||
|
Mathf.Clamp(GlobalPosition.Y, bounds.Position.Y, bounds.End.Y)
|
||
|
);
|
||
|
|
||
|
if (bounds.HasPoint(GlobalPosition)) Hide();
|
||
|
else Show();
|
||
|
}
|
||
|
|
||
|
private void SetMarkerRotation()
|
||
|
{
|
||
|
var sprite = GetNode<Sprite2D>("Sprite2D");
|
||
|
var angle = (GlobalPosition - sprite.GlobalPosition).Angle();
|
||
|
sprite.GlobalRotation = angle;
|
||
|
sprite.GetNode<Sprite2D>("Arrow").GlobalRotation = 0;
|
||
|
}
|
||
|
}
|