Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm just starting with XNA and I wanted to draw Debug Lines around my Texture/Sprite to help me.

Is there an easy way to do it with SpriteBatch? I haven't used the GraphicsDevice yet to draw....


share|improve this question
Just google search draw lines spritebatch... Basically it works by streching and rotation 1x1 texture – Kikaimaru Apr 25 '12 at 17:03
so i have to add a 1 pixel texuture to my content? Is there an easier way perhaps? – Setheron Apr 25 '12 at 17:04
You can dynamicaly create it when creating spring batch (i have subclass SpringBatchEx), new Texture2D() then SetData and set white color, it will be in some of google results :) – Kikaimaru Apr 25 '12 at 17:05
Me and a friend have made an open-source project that helps with drawing lines, rectangles, and other "primitives" in XNA: – John McDonald Apr 25 '12 at 17:20
up vote 4 down vote accepted

I would suggest to create subclass of SpriteBatch that would have DrawLine and DrawRectangle function and in constructor create 1x1 texture.

share|improve this answer
Im testing out that method but doesn't work.. need to investigate – Setheron Apr 25 '12 at 17:37

Check out this forum post in which the poster details how he is making spriteBatch draw in wireframe mode.

Basically you just need to change your draw code to this;

RasterizerState state = new RasterizerState();
state.FillMode = FillMode.WireFrame;
spriteBatch.GraphicsDevice.RasterizerState = state;

spriteBatch.Draw(sprite, position, Color.White);


And obviously change "spriteBatch.Draw(sprite, position, Color.White)" to be a loop drawing all of your sprites.

share|improve this answer
doesn't seem to show me anything, but maybe my Rectangle for my sprite is out of screen.. – Setheron Apr 25 '12 at 18:49
Maybe, just try rendering with the line ...RasterizerState = state; commented out. Then you should just be rendering as normal. – OriginalDaemon Apr 25 '12 at 20:04
The most important thing, basically, is to use SpriteSortMode.Immediate and spriteBatch.GraphicsDevice.RasterizerState = FillMode.WireFrame; The rest of your rendering code should stay the same. – OriginalDaemon Apr 25 '12 at 20:05
I didn't see Immediate.. I'll try again – Setheron Apr 25 '12 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.