fixed animation bugs

This commit is contained in:
2022-12-11 19:17:37 +01:00
parent 6c57a23f85
commit de7d239282

View File

@@ -8,13 +8,22 @@ public partial class player : CharacterBody2D
[Export] [Export]
public int speed = 400; public int speed = 400;
public Vector2 velocity; public Vector2 velocity;
public AnimatedSprite2D animatedSprite;
public override void _Ready()
{
animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
}
public void ChangeProcess(bool process)
{
if (process) ProcessMode = ProcessModeEnum.Inherit; else ProcessMode = ProcessModeEnum.Disabled;
animatedSprite.Frame = 0;
}
public override void _PhysicsProcess(double delta) public override void _PhysicsProcess(double delta)
{ {
velocity = Input.GetVector("move_left", "move_right", "move_up", "move_down").LimitLength(1); velocity = Input.GetVector("move_left", "move_right", "move_up", "move_down").LimitLength(1);
MoveAndCollide(velocity * speed * (float)delta); MoveAndCollide(velocity * speed * (float)delta);
} }
public void ChangeProcess(bool process){ if(process) ProcessMode = ProcessModeEnum.Inherit; else ProcessMode = ProcessModeEnum.Disabled; }
public override void _Process(double delta) public override void _Process(double delta)
{ {
//set ray_cast target position //set ray_cast target position
@@ -27,7 +36,6 @@ public partial class player : CharacterBody2D
if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding()) if (Input.IsActionJustPressed("ui_accept") && GetNode<RayCast2D>("ray_cast_2d").IsColliding())
GetNode<RayCast2D>("ray_cast_2d").GetCollider().Call("OnInteraction", playerName); GetNode<RayCast2D>("ray_cast_2d").GetCollider().Call("OnInteraction", playerName);
//animation system (with controller support wcih cant get normalized vector) //animation system (with controller support wcih cant get normalized vector)
var animatedSprite = GetNode<AnimatedSprite2D>("AnimatedSprite2D");
if (velocity.Length() != 0) if (velocity.Length() != 0)
animatedSprite.Play(); animatedSprite.Play();
else else