diff --git a/AnimationsFileCreator/Program.cs b/AnimationsFileCreator/Program.cs index 1287e6f..dc2bf5b 100644 --- a/AnimationsFileCreator/Program.cs +++ b/AnimationsFileCreator/Program.cs @@ -40,6 +40,7 @@ namespace AnimationsFileCreator string id = Console.ReadLine(); Console.WriteLine("Введите 1 если анимация зациклена, и 0 если нет"); AnimationContainer container = new AnimationContainer(); + int a = int.Parse(Console.ReadLine()); if (a==1) { @@ -49,6 +50,10 @@ namespace AnimationsFileCreator { 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.FrameTime = new System.Collections.Generic.List>(); container.FrameTime.Add(new Tuple(0, interval)); diff --git a/DangerousD/GameCore/Graphics/AnimationContainer.cs b/DangerousD/GameCore/Graphics/AnimationContainer.cs index 863f260..c50cb2b 100644 --- a/DangerousD/GameCore/Graphics/AnimationContainer.cs +++ b/DangerousD/GameCore/Graphics/AnimationContainer.cs @@ -23,6 +23,10 @@ namespace DangerousD.GameCore.Graphics public int FramesCount { get; set; } [JsonProperty("isCycle")] public bool IsCycle { get; set; } + [JsonProperty("offset")] + public Vector2 Offset { get; set; } + + } } diff --git a/DangerousD/GameCore/Graphics/GraphicsComponent.cs b/DangerousD/GameCore/Graphics/GraphicsComponent.cs index 3dfed09..f858f3f 100644 --- a/DangerousD/GameCore/Graphics/GraphicsComponent.cs +++ b/DangerousD/GameCore/Graphics/GraphicsComponent.cs @@ -129,8 +129,24 @@ namespace DangerousD.GameCore.Graphics 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); }