diff --git a/MLEM.Extended/Extensions/SpriteBatchExtensions.cs b/MLEM.Extended/Extensions/SpriteBatchExtensions.cs index 376ac30..4596625 100644 --- a/MLEM.Extended/Extensions/SpriteBatchExtensions.cs +++ b/MLEM.Extended/Extensions/SpriteBatchExtensions.cs @@ -26,5 +26,23 @@ namespace MLEM.Extended.Extensions { batch.Draw(texture, destinationRectangle, null, color); } + /// + /// Draws a grid of tile outlines reminiscent of graph paper. + /// + /// The sprite batch to draw with + /// The top left coordinate of the grid + /// The size of each tile + /// The amount of tiles in the x and y axes + /// The color to draw the grid outlines in + /// The thickness of each grid line. Defaults to 1. + public static void DrawGrid(this SpriteBatch batch, Vector2 start, Vector2 tileSize, Point tileCount, Color gridColor, float gridThickness = 1) { + for (var y = 0; y < tileCount.Y; y++) { + for (var x = 0; x < tileCount.X; x++) + batch.DrawRectangle(start + new Vector2(x, y) * tileSize, tileSize, gridColor, gridThickness / 2); + } + var size = tileSize * tileCount.ToVector2() + new Vector2(gridThickness); + batch.DrawRectangle(start - new Vector2(gridThickness / 2), size, gridColor, gridThickness / 2); + } + } } \ No newline at end of file diff --git a/Sandbox/GameImpl.cs b/Sandbox/GameImpl.cs index 12a27f6..21844e0 100644 --- a/Sandbox/GameImpl.cs +++ b/Sandbox/GameImpl.cs @@ -131,6 +131,7 @@ namespace Sandbox { this.SpriteBatch.FillRectangle(new RectangleF(400, 20, 400, 1000), Color.Green); font.DrawString(this.SpriteBatch, this.tokenized.DisplayString, new Vector2(400, 20), Color.White * 0.25F, 0, Vector2.Zero, 5, SpriteEffects.None, 0); this.tokenized.Draw(time, this.SpriteBatch, new Vector2(400, 20), font, Color.White, 5, 0); + this.SpriteBatch.DrawGrid(new Vector2(30, 30), new Vector2(40, 60), new Point(10, 5), Color.Yellow, 3); this.SpriteBatch.End(); }; this.OnUpdate += (g, time) => {