From b14e869e443ed025aea56b7d7f37d1275acc3d92 Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Tue, 20 Aug 2024 04:19:02 +0300 Subject: [PATCH] Add cycling animation --- .../GameManagers/AssetsManager/AssetManager.cs | 2 +- .../Entities/LivingEntities/Player/Player.cs | 4 ++-- ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs | 11 +++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ZoFo/GameCore/GameManagers/AssetsManager/AssetManager.cs b/ZoFo/GameCore/GameManagers/AssetsManager/AssetManager.cs index 334957f..78fbf78 100644 --- a/ZoFo/GameCore/GameManagers/AssetsManager/AssetManager.cs +++ b/ZoFo/GameCore/GameManagers/AssetsManager/AssetManager.cs @@ -12,7 +12,7 @@ public class AssetManager public AssetContainer Player = new() { - Animations = [ "player_look_down" ], + Animations = [ "player_look_down", "player_run_up"], IdleAnimation = "player_look_down" }; } \ No newline at end of file diff --git a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs index c76c1bc..baec6d3 100644 --- a/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs +++ b/ZoFo/GameCore/GameObjects/Entities/LivingEntities/Player/Player.cs @@ -46,8 +46,8 @@ public class Player : LivingEntity switch(AppManager.Instance.InputManager.ConvertVector2ToState(InputPlayerRotation)) { case ScopeState.Top: - //if ((graphicsComponent as AnimatedGraphicsComponent).CurrentAnimation.TextureName!="player_run_up") - //(graphicsComponent as AnimatedGraphicsComponent).Star ("player_run_up"); + if ((graphicsComponent as AnimatedGraphicsComponent).CurrentAnimation.TextureName!="player_run_up") + (graphicsComponent as AnimatedGraphicsComponent).StartCyclingAnimation("player_run_up"); break; case ScopeState.Down: StartAnimation("player_run_down"); diff --git a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs index 85c4a7e..86af079 100644 --- a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs @@ -138,6 +138,17 @@ namespace ZoFo.GameCore.Graphics SetInterval(); } + + public void StartCyclingAnimation(string startedanimationId) + { + currentFrame = 0; + currentAnimation = animations.Find(x => x.Id == startedanimationId); + currentAnimation.IsCycle = true; + + buildSourceRectangle(); + SetInterval(); + + } public void StopAnimation() {