particles/ParticleNode.cs
2022-01-17 23:52:42 -05:00

38 lines
1.1 KiB
C#

using Godot;
// ReSharper disable once CheckNamespace
// ReSharper disable once ClassNeverInstantiated.Global
public class ParticleNode : Node2D
{
private Label _labelNode;
private Sprite _spriteNode;
public Vector2 CurrentSimulationPosition = new Vector2();
public Vector2 LastSimulationPosition;
public bool WasTeleportedLast = true;
public int SimulationId;
public override void _Ready()
{
_spriteNode = GetNode<Sprite>("Sprite");
_labelNode = GetNode<Label>("Label");
}
public override void _Process(float delta)
{
Position = WasTeleportedLast == false
? LastSimulationPosition.LinearInterpolate(CurrentSimulationPosition,
GetParent<Node2D>().GetParent<ParticleSimulationScene>().PhysicsInterpolationFraction)
: CurrentSimulationPosition;
}
public void SetLabelText(string text)
{
_labelNode.Text = text;
}
public void SetColor(float hue, float saturation, float opacity)
{
_spriteNode.Modulate = Color.FromHsv(hue, saturation, 1, opacity);
}
}