mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
48 lines
No EOL
1 KiB
C#
48 lines
No EOL
1 KiB
C#
using Godot;
|
|
|
|
public partial class PlayerAnimationProvider : Node2D
|
|
{
|
|
[Export]
|
|
public AnimatedSprite2D _animatedSprite {get; private set;}
|
|
|
|
[ExportCategory("Animation Names")]
|
|
[Export]
|
|
public string WalkRightAnimationName {get; private set;} = "walk_right";
|
|
|
|
[Export]
|
|
public string WalkLeftAnimationName {get; private set;} = "walk_left";
|
|
[Export]
|
|
public string WalkDownAnimationName {get; private set;} = "walk_down";
|
|
[Export]
|
|
public string WalkUpAnimationName {get; private set;} = "walk_up";
|
|
|
|
public void SetAnimation(Vector2 velocity)
|
|
{
|
|
if (velocity.X == 0 && velocity.Y == 0)
|
|
{
|
|
_animatedSprite.SpeedScale = 0;
|
|
}
|
|
else
|
|
{
|
|
_animatedSprite.SpeedScale = 1;
|
|
}
|
|
|
|
if (velocity.X > 0)
|
|
{
|
|
_animatedSprite.Play(WalkRightAnimationName);
|
|
}
|
|
else if (velocity.X < 0)
|
|
{
|
|
_animatedSprite.Play(WalkLeftAnimationName);
|
|
}
|
|
else if (velocity.Y > 0)
|
|
{
|
|
_animatedSprite.Play(WalkDownAnimationName);
|
|
}
|
|
else if (velocity.Y < 0)
|
|
{
|
|
_animatedSprite.Play(WalkUpAnimationName);
|
|
}
|
|
}
|
|
|
|
} |