From 22c595878dee56dc71dbc1db9508e50ff7fdd23e Mon Sep 17 00:00:00 2001 From: Mootfrost777 Date: Sun, 18 Aug 2024 18:12:43 +0300 Subject: [PATCH] Add flipping and rotation around left-top edge --- .../Graphics/AnimatedGraphicsComponent.cs | 9 ++++++--- ZoFo/GameCore/Graphics/GraphicsComponent.cs | 3 +++ ZoFo/GameCore/Graphics/IGraphicsComponent.cs | 16 ---------------- .../Graphics/StaticGraphicsComponent.cs | 17 ++++++++++------- 4 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 ZoFo/GameCore/Graphics/IGraphicsComponent.cs diff --git a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs index d590462..bc2d8ff 100644 --- a/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/AnimatedGraphicsComponent.cs @@ -163,6 +163,7 @@ namespace ZoFo.GameCore.Graphics } interval--; + } public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch) @@ -187,8 +188,9 @@ namespace ZoFo.GameCore.Graphics destinationRectangle.Y -= CameraPosition.Y; destinationRectangle = Scaling(destinationRectangle); - _spriteBatch.Draw(texture, - destinationRectangle, sourceRectangle, Color.White); + + _spriteBatch.Draw(texture, destinationRectangle, sourceRectangle, Color.White, Rotation, + Vector2.Zero, Flip, 0); } public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) { @@ -213,7 +215,8 @@ namespace ZoFo.GameCore.Graphics destinationRectangle = Scaling(destinationRectangle); _spriteBatch.Draw(texture, - destinationRectangle, sourceRectangle, Color.White); + destinationRectangle, sourceRectangle, Color.White, 0, + Vector2.Zero, Flip, 0); } private void buildSourceRectangle() { diff --git a/ZoFo/GameCore/Graphics/GraphicsComponent.cs b/ZoFo/GameCore/Graphics/GraphicsComponent.cs index c71b0c3..3fa8fa4 100644 --- a/ZoFo/GameCore/Graphics/GraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/GraphicsComponent.cs @@ -9,6 +9,9 @@ public abstract class GraphicsComponent public static int scaling = 1; public string mainTextureName;//TODO костыль - пофиксить + public SpriteEffects Flip = SpriteEffects.None; + public float Rotation; + public abstract void LoadContent(); public abstract void Update(); public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch); diff --git a/ZoFo/GameCore/Graphics/IGraphicsComponent.cs b/ZoFo/GameCore/Graphics/IGraphicsComponent.cs deleted file mode 100644 index 50e2424..0000000 --- a/ZoFo/GameCore/Graphics/IGraphicsComponent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace ZoFo.GameCore.Graphics; - -public interface IGraphicsComponent -{ - public Rectangle ObjectDrawRectangle { get; set; } - public static int scaling = 1; - public string mainTextureName { get; set; }//TODO костыль - пофиксить - - public abstract void LoadContent(); - public abstract void Update(); - public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch); - public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle); -} \ No newline at end of file diff --git a/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs b/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs index 3e2fd6c..a631c5d 100644 --- a/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs +++ b/ZoFo/GameCore/Graphics/StaticGraphicsComponent.cs @@ -8,7 +8,6 @@ using ZoFo.GameCore.GUI; namespace ZoFo.GameCore.Graphics { - public class StaticGraphicsComponent : GraphicsComponent { private Texture2D texture; @@ -18,7 +17,7 @@ namespace ZoFo.GameCore.Graphics { LoadContent(); } - + public StaticGraphicsComponent(string textureName) { BuildComponent(textureName); @@ -29,7 +28,7 @@ namespace ZoFo.GameCore.Graphics { _textureName = textureName; } - + public override void LoadContent() { @@ -37,7 +36,7 @@ namespace ZoFo.GameCore.Graphics { return; } - + texture = AppManager.Instance.Content.Load(_textureName); } @@ -53,11 +52,14 @@ namespace ZoFo.GameCore.Graphics destinationRectangle.X -= CameraPosition.X; destinationRectangle.Y -= CameraPosition.Y; destinationRectangle = Scaling(destinationRectangle); - _spriteBatch.Draw(texture, destinationRectangle, Color.White); + _spriteBatch.Draw(texture, destinationRectangle, texture.Bounds, Color.White, Rotation, + Vector2.Zero, Flip, 0); } public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle) { + // Uncomment to go brrrr + //Rotation = new Random().Next(1, 365); DebugHUD.Instance.Log("draw "); destinationRectangle.X -= CameraPosition.X; @@ -65,7 +67,8 @@ namespace ZoFo.GameCore.Graphics destinationRectangle = Scaling(destinationRectangle); _spriteBatch.Draw(texture, - destinationRectangle, sourceRectangle, Color.White); + destinationRectangle, sourceRectangle, Color.White, Rotation, + Vector2.Zero, Flip, 0); } } -} +} \ No newline at end of file