First make a 1x1 pixel white texture for the rectangle:
var t = new Texture2D(GraphicsDevice, 1, 1); t.SetData(new[] { Color.White });
Now you need to display the rectangle - suppose the rectangle is called a rectangle . For rendering a filled block, it is very simple - make sure tint Color is the color you want. Just use this code:
spriteBatch.Draw(t, rectangle, Color.Black);
For the border, this is more complicated. You should draw 4 lines that make up the outline (the rectangle here is r ):
int bw = 2; // Border width spriteBatch.Draw(t, new Rectangle(r.Left, r.Top, bw, r.Height), Color.Black); // Left spriteBatch.Draw(t, new Rectangle(r.Right, r.Top, bw, r.Height), Color.Black); // Right spriteBatch.Draw(t, new Rectangle(r.Left, r.Top, r.Width , bw), Color.Black); // Top spriteBatch.Draw(t, new Rectangle(r.Left, r.Bottom, r.Width, bw), Color.Black); // Bottom
Hope this helps!
Callum rogers
source share