Can we get one tutorial on how to draw things on the screen

Aug 3, 2010 at 4:59 AM

I think I am doing it wrong because I use my physics info to render, so i do things like

 

spriteBatch.Draw(mazeBox, mazeBody.Position / 0.01f, Color.White)

 But according to http://box2dxna.codeplex.com/Thread/View.aspx?ThreadId=219966 blecki in this thread.

 

"Your physics information is not your rendering information. Create some transforms based on the maze's position and rotation, then just go through the same data you used to create the maze and draw boxes."

 

So My question is what is the correct way of drawing things using Box2D. A simple example is fine. It could be a ball dropping from (10,10) to say (10,500).

Aug 3, 2010 at 11:41 AM
I was just pointing out that you don't have to figure out how to draw a fixture. Specifically, if you've got a bunch of polygon shapes in the simulation, you must also have this data outside Box2D.XNA since you used it to create the shapes; so don't go digging through Box2D for the data. You have it already. Your way of drawing a maze piece works fine, though if the maze is static it may be more efficient to put the entire maze in one body, set a transform once, and then use your original maze info to draw the walls without touching the fixture list at all.
Coordinator
Aug 3, 2010 at 6:40 PM

Take a look at this blog post by Brandon:

http://blogs.msdn.com/b/brandf/archive/2010/01/04/adding-2d-physics-to-your-xna-game-studio-game-part-1.aspx

 

It at least shows how to render circles, but for any shape you can use the same technique with a matching sprite.

 

There is also the debug drawer that comes with Box2D.XNA.Testbed, all of the testbed samples use this drawer.  It is not meant to be used with live games, but you could adapt the portions you need for general debug or vector graphics.