Merge pull request #68 from progtime-net/texture-flipping

Add flipping and rotation around left-top edge
This commit is contained in:
Andrey 2024-08-18 18:14:47 +03:00 committed by GitHub
commit 7244981e86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 19 additions and 26 deletions

View file

@ -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()
{

View file

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

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
{
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<Texture2D>(_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);
}
}
}
}