You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
795 B
36 lines
795 B
using Godot;
|
|
|
|
namespace Babushka.scripts.CSharp.Common;
|
|
|
|
/// <summary>
|
|
/// Switches between two available Sprite Options.
|
|
/// </summary>
|
|
public partial class SpriteSwitcher2D : Node2D
|
|
{
|
|
[Export] private Sprite2D _firstSprite;
|
|
[Export] private Sprite2D _secondSprite;
|
|
[Export] private bool _state = true;
|
|
|
|
[Signal]
|
|
public delegate void SwitchEventHandler(bool state);
|
|
|
|
public override void _Ready()
|
|
{
|
|
SetState();
|
|
}
|
|
|
|
public void SwitchState()
|
|
{
|
|
_state = !_state;
|
|
EmitSignal(SignalName.Switch, _state);
|
|
SetState();
|
|
}
|
|
|
|
private void SetState()
|
|
{
|
|
if(_firstSprite != null)
|
|
_firstSprite.Visible = _state;
|
|
if(_secondSprite != null)
|
|
_secondSprite.Visible = !_state;
|
|
}
|
|
} |