ReworkingAnimator

This commit is contained in:
Timofey06 2023-08-14 20:01:50 +03:00
parent 3ca1f7a9db
commit 0bf49c55e9
3 changed files with 49 additions and 16 deletions

View file

@ -37,7 +37,17 @@ namespace AnimationsFileCreator
rectangle.Height = int.Parse(Console.ReadLine());
Console.WriteLine("Введите название для этого файла - id анимации");
string id = Console.ReadLine();
Console.WriteLine("Введите 1 если анимация зациклена, и 0 если нет");
AnimationContainer container = new AnimationContainer();
int a = int.Parse(Console.ReadLine());
if (a==1)
{
container.IsCycle = true;
}
else
{
container.IsCycle = false;
}
container.FramesCount = framesCount;
container.FrameTime = new System.Collections.Generic.List<Tuple<int, int>>();
container.FrameTime.Add(new Tuple<int, int>(0, interval));
@ -49,8 +59,6 @@ namespace AnimationsFileCreator
StreamWriter writer = new StreamWriter(id);
writer.WriteLine(json);
writer.Close();
}
}
}

View file

@ -21,6 +21,8 @@ namespace DangerousD.GameCore.Graphics
public int TextureFrameInterval { get; set; }
[JsonProperty("framesCount")]
public int FramesCount { get; set; }
[JsonProperty("isCycle")]
public bool IsCycle { get; set; }
}
}

View file

@ -3,6 +3,7 @@ using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace DangerousD.GameCore.Graphics
@ -13,28 +14,33 @@ namespace DangerousD.GameCore.Graphics
private List<Texture2D> textures;
private List<string> texturesNames;
private AnimationContainer currentAnimation;
private AnimationContainer neitralAnimation;
//private SpriteBatch _spriteBatch;
private string lastAnimationId;
private int currentFrame;
private int interval;
private int lastInterval;
private Rectangle sourceRectangle;
public GraphicsComponent(List<string> animationsId)
public GraphicsComponent(List<string> animationsId, string neitralAnimationId)
{
//this._spriteBatch = _spriteBatch;
currentFrame = 0;
lastInterval = 1;
lastAnimationId = null;
LoadAnimations(animationsId);
LoadAnimations(animationsId,neitralAnimationId);
}
private void LoadAnimations(List<string> animationsId)
private void LoadAnimations(List<string> animationsId, string neitralAnimationId)
{
animations = new List<AnimationContainer>();
foreach (var id in animationsId)
{
animations.Add( GameManager.builder.animations.Find(x => x.Id == id));
if (id==neitralAnimationId)
{
neitralAnimation = animations.Last();
}
}
}
public void LoadContent(ContentManager content)
@ -52,22 +58,39 @@ namespace DangerousD.GameCore.Graphics
}
}
}
public void DrawAnimation(Rectangle destinationRectangle, string animationId, SpriteBatch _spriteBatch)
public void StartAnimation(string startedanimationId)
{
currentFrame = 0;
currentAnimation = animations.Find(x => x.Id == startedanimationId);
buildSourceRectangle();
SetInterval();
}
public void StopAnimation()
{
currentFrame = 0;
interval = 0;
currentAnimation = neitralAnimation;
buildSourceRectangle();
SetInterval();
}
public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
{
if (animationId != lastAnimationId)
{
currentFrame = 0;
currentAnimation = animations.Find(x => x.Id == animationId);
buildSourceRectangle();
SetInterval();
}
if (interval == 0)
{
currentFrame++;
if (currentAnimation.FramesCount - 1 <= currentFrame)
{
if (!currentAnimation.IsCycle)
{
currentAnimation = neitralAnimation;
}
currentFrame = 0;
}
buildSourceRectangle();