I’ve been using this great XNA lib for drawing 2D lines, circles, and shapes for awhile. I’m using an older version that I cleaned up to minimize garbage collection ( to none! ), but the code is still being updated by CentauriBoy on the AppHub forums, and recently got anti-aliasing and filled shapes added.
Home thread on XNA forums: http://forums.create.msdn.com/forums/t/7414.aspx
A simple example I use to draw a laser beam
beam = new BasicPrimitives(Game.GraphicsDevice); beam.ClearVectors() beam.AddVector( this.position ); // Vector2 beam.AddVector( target.position ); // Vector2 beam.Colour = new Color(255, 255, 255, 180); beam.Thickness = 1; beam.RenderPolygonPrimitive(spriteBatch);
Notice the color in this example is slightly transparent. For my laser beams, I’m stacking 3 to 5 of these lines with slight offsets to get a glow effect. Also note that using ‘new Color’ in a draw loop is bad practice. You never want to be creating anything in your loops because it will later need to be removed by the garbage collector. To eliminate garbage collection, you would define your colors once in a constructor, and re-use them.