I am new to XNA and right now I am drawing a rectangle using this code:
// Calculate particle intensity
intense = (int)((float)part.Life / PARTICLES_MAX_LIFE);
// Generate pen for the particle
pen = new Pen(Color.FromArgb(intense * m_Color.R , intense * m_Color.G, intense * m_Color.B));
// Draw particle
g.DrawRectangle(pen, part.Position.X, part.Position.Y,
Math.Max(1,8 * part.Life / PARTICLES_MAX_LIFE),
Math.Max(1,8 * part.Life / PARTICLES_MAX_LIFE));
pen.Dispose();
All the ways to fill a rectangle with color that I found online dosen't seems to apply to the way I draw my rectangle. How can I fill it with color?
Your code appears to be most likely made for GDI and not XNA, therefor it is not working correctly.
However, XNA includes a very useful Rectangle structure.
This means that you can "stretch" an image to fill a rectangle, so create a new Texture2D that is 1x1 pixels, and stretch the dimensions when drawn to increase the size.. (Or you could load one)
Texture2D texture = new Texture2D(graphics, 1, 1, false, SurfaceFormat.Color);
texture.SetData<Color>(new Color[] { Color.White });
return texture;
You can use this small texture in conjunction with the Rectangle based overload method for SpriteBatch
spriteBatch.Draw(texture, new Rectangle(X, Y, Width, Height), Color.White);
Change the Width, Height, Position and Color to your liking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With