Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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....

Thanks!

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: bitbucket.org/jcpmcdonald/2d-xna-primitives/wiki/Home –  John McDonald Apr 25 '12 at 17:20
add comment

2 Answers

up vote 4 down vote accepted

http://www.xnawiki.com/index.php/Drawing_2D_lines_without_using_primitives

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
add comment

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;

spriteBatch.Begin(SpriteSortMode.Immediate,BlendState.Opaque);
RasterizerState state = new RasterizerState();
state.FillMode = FillMode.WireFrame;
spriteBatch.GraphicsDevice.RasterizerState = state;

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

spriteBatch.End();

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
add comment

Your Answer

 
discard

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.