✨ Off screen marker
This commit is contained in:
35
Scripts/Effects/OffScreenMarker.cs
Normal file
35
Scripts/Effects/OffScreenMarker.cs
Normal file
@ -0,0 +1,35 @@
|
||||
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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user