2
\$\begingroup\$

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!

\$\endgroup\$
4
  • \$\begingroup\$ Just google search draw lines spritebatch... Basically it works by streching and rotation 1x1 texture \$\endgroup\$
    – Kikaimaru
    Commented Apr 25, 2012 at 17:03
  • \$\begingroup\$ so i have to add a 1 pixel texuture to my content? Is there an easier way perhaps? \$\endgroup\$
    – Setheron
    Commented Apr 25, 2012 at 17:04
  • \$\begingroup\$ 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 :) \$\endgroup\$
    – Kikaimaru
    Commented Apr 25, 2012 at 17:05
  • \$\begingroup\$ 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 \$\endgroup\$ Commented Apr 25, 2012 at 17:20

2 Answers 2

4
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Im testing out that method but doesn't work.. need to investigate \$\endgroup\$
    – Setheron
    Commented Apr 25, 2012 at 17:37
0
\$\begingroup\$

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.

\$\endgroup\$
4
  • \$\begingroup\$ doesn't seem to show me anything, but maybe my Rectangle for my sprite is out of screen.. \$\endgroup\$
    – Setheron
    Commented Apr 25, 2012 at 18:49
  • \$\begingroup\$ Maybe, just try rendering with the line ...RasterizerState = state; commented out. Then you should just be rendering as normal. \$\endgroup\$ Commented Apr 25, 2012 at 20:04
  • \$\begingroup\$ 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. \$\endgroup\$ Commented Apr 25, 2012 at 20:05
  • \$\begingroup\$ I didn't see Immediate.. I'll try again \$\endgroup\$
    – Setheron
    Commented Apr 25, 2012 at 20:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .