TestWorkingVersionOfAnimator

This commit is contained in:
Timofey06 2023-08-15 17:15:14 +03:00
parent 2d33e13283
commit cb9b3664a4
3 changed files with 26 additions and 1 deletions

View file

@ -40,6 +40,7 @@ namespace AnimationsFileCreator
string id = Console.ReadLine(); string id = Console.ReadLine();
Console.WriteLine("Введите 1 если анимация зациклена, и 0 если нет"); Console.WriteLine("Введите 1 если анимация зациклена, и 0 если нет");
AnimationContainer container = new AnimationContainer(); AnimationContainer container = new AnimationContainer();
int a = int.Parse(Console.ReadLine()); int a = int.Parse(Console.ReadLine());
if (a==1) if (a==1)
{ {
@ -49,6 +50,10 @@ namespace AnimationsFileCreator
{ {
container.IsCycle = false; container.IsCycle = false;
} }
Console.WriteLine("Введите отклонение анимации от стандартной (сначала X, потом enter, потом Y): ");
int otklx = int.Parse(Console.ReadLine());
int otkly = int.Parse(Console.ReadLine());
container.Offset =new Vector2(otklx,otkly);
container.FramesCount = framesCount; container.FramesCount = framesCount;
container.FrameTime = new System.Collections.Generic.List<Tuple<int, int>>(); container.FrameTime = new System.Collections.Generic.List<Tuple<int, int>>();
container.FrameTime.Add(new Tuple<int, int>(0, interval)); container.FrameTime.Add(new Tuple<int, int>(0, interval));

View file

@ -23,6 +23,10 @@ namespace DangerousD.GameCore.Graphics
public int FramesCount { get; set; } public int FramesCount { get; set; }
[JsonProperty("isCycle")] [JsonProperty("isCycle")]
public bool IsCycle { get; set; } public bool IsCycle { get; set; }
[JsonProperty("offset")]
public Vector2 Offset { get; set; }
} }
} }

View file

@ -129,8 +129,24 @@ namespace DangerousD.GameCore.Graphics
public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch) public void DrawAnimation(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
{ {
Texture2D texture = textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)];
float scale;
if (currentAnimation.Offset.X!=0)
{
destinationRectangle.X -= (int)currentAnimation.Offset.X;
scale=destinationRectangle.Height/sourceRectangle.Height;
destinationRectangle.Width = (int)(sourceRectangle.Width * scale);
}
else if (currentAnimation.Offset.Y != 0)
{
destinationRectangle.Y -= (int)currentAnimation.Offset.Y;
scale = destinationRectangle.Width / sourceRectangle.Width;
destinationRectangle.Height = (int)(sourceRectangle.Height * scale);
}
_spriteBatch.Draw(textures[texturesNames.FindIndex(x => x == currentAnimation.TextureName)], _spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White); destinationRectangle, sourceRectangle, Color.White);
} }