1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-11-22 12:58:33 +01:00

added DrawGrid to MLEM.Extended

This commit is contained in:
Ellpeck 2020-05-23 22:31:20 +02:00
parent d1a895e3a1
commit 12cc7a02c7
2 changed files with 19 additions and 0 deletions

View file

@ -26,5 +26,23 @@ namespace MLEM.Extended.Extensions {
batch.Draw(texture, destinationRectangle, null, color); batch.Draw(texture, destinationRectangle, null, color);
} }
/// <summary>
/// Draws a grid of tile outlines reminiscent of graph paper.
/// </summary>
/// <param name="batch">The sprite batch to draw with</param>
/// <param name="start">The top left coordinate of the grid</param>
/// <param name="tileSize">The size of each tile</param>
/// <param name="tileCount">The amount of tiles in the x and y axes</param>
/// <param name="gridColor">The color to draw the grid outlines in</param>
/// <param name="gridThickness">The thickness of each grid line. Defaults to 1.</param>
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);
}
} }
} }

View file

@ -131,6 +131,7 @@ namespace Sandbox {
this.SpriteBatch.FillRectangle(new RectangleF(400, 20, 400, 1000), Color.Green); 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); 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.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.SpriteBatch.End();
}; };
this.OnUpdate += (g, time) => { this.OnUpdate += (g, time) => {