Add flipping and rotation around left-top edge

This commit is contained in:
Mootfrost777 2024-08-18 18:12:43 +03:00
parent 97cd62759c
commit 22c595878d
4 changed files with 19 additions and 26 deletions

View file

@ -163,6 +163,7 @@ namespace ZoFo.GameCore.Graphics
} }
interval--; interval--;
} }
public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch) public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch)
@ -187,8 +188,9 @@ namespace ZoFo.GameCore.Graphics
destinationRectangle.Y -= CameraPosition.Y; destinationRectangle.Y -= CameraPosition.Y;
destinationRectangle = Scaling(destinationRectangle); 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) public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
{ {
@ -213,7 +215,8 @@ namespace ZoFo.GameCore.Graphics
destinationRectangle = Scaling(destinationRectangle); destinationRectangle = Scaling(destinationRectangle);
_spriteBatch.Draw(texture, _spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White); destinationRectangle, sourceRectangle, Color.White, 0,
Vector2.Zero, Flip, 0);
} }
private void buildSourceRectangle() private void buildSourceRectangle()
{ {

View file

@ -9,6 +9,9 @@ public abstract class GraphicsComponent
public static int scaling = 1; public static int scaling = 1;
public string mainTextureName;//TODO костыль - пофиксить public string mainTextureName;//TODO костыль - пофиксить
public SpriteEffects Flip = SpriteEffects.None;
public float Rotation;
public abstract void LoadContent(); public abstract void LoadContent();
public abstract void Update(); public abstract void Update();
public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch); public abstract void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch);

View file

@ -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);
}

View file

@ -8,7 +8,6 @@ using ZoFo.GameCore.GUI;
namespace ZoFo.GameCore.Graphics namespace ZoFo.GameCore.Graphics
{ {
public class StaticGraphicsComponent : GraphicsComponent public class StaticGraphicsComponent : GraphicsComponent
{ {
private Texture2D texture; private Texture2D texture;
@ -53,11 +52,14 @@ namespace ZoFo.GameCore.Graphics
destinationRectangle.X -= CameraPosition.X; destinationRectangle.X -= CameraPosition.X;
destinationRectangle.Y -= CameraPosition.Y; destinationRectangle.Y -= CameraPosition.Y;
destinationRectangle = Scaling(destinationRectangle); 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) public override void Draw(Rectangle destinationRectangle, SpriteBatch _spriteBatch, Rectangle sourceRectangle)
{ {
// Uncomment to go brrrr
//Rotation = new Random().Next(1, 365);
DebugHUD.Instance.Log("draw "); DebugHUD.Instance.Log("draw ");
destinationRectangle.X -= CameraPosition.X; destinationRectangle.X -= CameraPosition.X;
@ -65,7 +67,8 @@ namespace ZoFo.GameCore.Graphics
destinationRectangle = Scaling(destinationRectangle); destinationRectangle = Scaling(destinationRectangle);
_spriteBatch.Draw(texture, _spriteBatch.Draw(texture,
destinationRectangle, sourceRectangle, Color.White); destinationRectangle, sourceRectangle, Color.White, Rotation,
Vector2.Zero, Flip, 0);
} }
} }
} }