Drawing Multiple Bodies using diffrent Textures?

Jun 22, 2010 at 11:00 PM

private void AddBox(Vector2 position)
            var boxShape = new PolygonShape();
            boxShape.SetAsBox(40f, 40f);

            var Bodydef = new BodyDef();
            Bodydef.type = BodyType.Dynamic;
            Bodydef.position = position;

            var myFixture = new FixtureDef();
            myFixture.density = 20.0f;
            myFixture.shape = boxShape;

            var myBody = myWorld.CreateBody(Bodydef);


private void AddCircle(Vector2 position)
CircleShape shape = new CircleShape();
			    shape._radius = 0.5f;

                FixtureDef fd = new FixtureDef();
			    fd.shape = shape;
			    fd.density = 1.0f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.Dynamic;
			    bd.position = new Vector2(-6.0f + 6.0f * i, 10.0f);
			    Body body = _world.CreateBody(bd);


            for(var b= myWorld.GetBodyList();b!=null;b=b.GetNext())
} spriteBatch.End();


How would i draw the circles with different textures and the boxes with different textures? Assuming i have 10 Circles created and 5 Boxes

Jun 23, 2010 at 3:23 AM

You need to create two square textures - one for the boxes, and one (with only the interior circle filled in) for the circles. Then you draw them with the position and rotation of the Box2D body.

Have a look at this msdn article for an overview on drawing rotated sprites.

Jun 24, 2010 at 3:06 AM

Also check out Brandon's blog posts about rendering sprites (and a Box2D sample):