Files
Babushka/scripts/CSharp/Common/SpriteSwitcher2D.cs
T

37 lines
835 B
C#
Raw Normal View History

2025-05-16 23:16:27 +02:00
using Godot;
namespace Babushka.scripts.CSharp.Common;
/// <summary>
/// Switches between two available Sprite Options.
/// </summary>
public partial class SpriteSwitcher2D : Node2D
{
[Export] private Sprite2D _activeSprite;
[Export] private Sprite2D _inactiveSprite;
[Export] private bool _active = false;
2025-05-16 23:16:27 +02:00
2025-05-16 23:16:27 +02:00
public override void _Ready()
{
SetSprites();
2025-05-16 23:16:27 +02:00
}
/// <summary>
/// Switches the State of the Sprites to the opposite.
/// Emits Switch Signal.
/// </summary>
public void SwitchState(bool state)
2025-05-16 23:16:27 +02:00
{
_active = state;
SetSprites();
2025-05-16 23:16:27 +02:00
}
private void SetSprites()
2025-05-16 23:16:27 +02:00
{
if(_activeSprite != null)
_activeSprite.Visible = _active;
if(_inactiveSprite != null)
_inactiveSprite.Visible = !_active;
2025-05-16 23:16:27 +02:00
}
}