Draw2DX.SpriteBatchX

The SpriteBatchX class is designed specificly to replace the Microsoft.Xna.SpriteBatch class. It is also very easy to do. Simply replace this:
SpriteBatch spriteBatch;
With this:
Draw2DX.SpriteBatchX spriteBatch;
And then replace this:
spriteBatch = new SpriteBatch(GraphicsDevice);
With this:
spriteBatch = new SpriteBatchX(GraphicsDevice);

And, that's it. No (additional) code changes are required when converting from SpriteBatch to SpriteBatchX, making it extremely easy to implant. However, preforming all of the operations that the original SpriteBatch can preform is not the only thing SpriteBatchX can do. It can also draw;
  • Points (square)
  • Lines
  • Circles
  • Ellipses
  • Rectangles
  • Gradient lines
Drawing each one is very simple. It is explained in the following code:

// Draw a point at (30, 360) that's orange and 16.2f pixels wide and tall.
spriteBatch.DrawDot(new Vector2(130f, 360f), 16.2f, Color.Orange);

// Draw a line from (200, 150) to (450, 40) that is red and 3.5f pixels wide:
spriteBatch.DrawLine(new Vector2(200f, 150f), new Vector2(450f, 40f), 3.5f, Color.Red);

// Draw a rectangle with the upper-left-hand corner at (200, 150) and the lower-right-hand corner at
// (400, 450) thats green and thats lines are 4.3 pixels wide. 
spriteBatch.DrawRectangle(new Vector2(200f, 150f), new Vector2(400f, 450f), Color.Green, 4.3f);

// Draw a white circle whose origin is (300, 350) with a radius of 100 and line width of 1.0f.
spriteBatch.DrawCircle(new Vector2(300, 350), 100f, Color.White, 1.0f);

// Draw a yellow ellipse whose origin is (300, 350) with an X radius of 100, a Y radius of 50 and line width of 2.0f.
spriteBatch.DrawElipse(new Vector2(300, 350), 100f, 50f, Color.Yellow, 2.0f);
The result is this:
Draw2DX output 1.bmp

NOTE: The above image is slightly different in color due to the file type I used (256 color bitmap) to reduce file size, and I reduced the image to only the part of the window that anything was drawn on. To see an different, more animated preview, download the current Draw2DX source code and run the demo.

Last edited Jul 23, 2010 at 6:03 PM by GamerMX1248, version 2

Comments

No comments yet.