Reworking 2D interactions
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user