Class Box2DDebugDraw
Box2D's own debug drawing, rendered through a ShapeBatch: every shape, joint, contact point, force, bounding box, island and body name the testbed can show, from one call a frame, with the testbed's toggles as properties.
public sealed class Box2DDebugDraw
- Inheritance
-
Box2DDebugDraw
Examples
var debugDraw = new Box2DDebugDraw(shapeBatch) { DrawContactPoints = true };
// each frame, after the simulation update
debugDraw.Draw(simulation);
Remarks
b2World_Draw calls back once per primitive (polygon, circle, capsule, line, point), and
each maps onto one batch call. Shapes and joints are drawn by default; everything else is off.
Lines are LinePixels wide on screen at any zoom. Points are sized in world units: Box2D's pixel size times PointScale. Text is drawn only through DrawString.
Constructors
Box2DDebugDraw(ShapeBatch)
Creates the adapter over a batch. Add the batch with game.AddShapeBatch() first.
public Box2DDebugDraw(ShapeBatch batch)
Parameters
batchShapeBatch
Properties
DrawBodyNames
Body names, through DrawString.
public bool DrawBodyNames { get; set; }
Property Value
DrawBounds
Axis-aligned bounding boxes of every shape.
public bool DrawBounds { get; set; }
Property Value
DrawContactFeatures
Contact feature ids as text.
public bool DrawContactFeatures { get; set; }
Property Value
DrawContactForces
Contact normal impulses, as lines scaled by ForceScale.
public bool DrawContactForces { get; set; }
Property Value
DrawContactNormals
Contact normals.
public bool DrawContactNormals { get; set; }
Property Value
DrawContactPoints
Contact points.
public bool DrawContactPoints { get; set; }
Property Value
DrawFrictionForces
Contact friction impulses, as lines scaled by ForceScale.
public bool DrawFrictionForces { get; set; }
Property Value
DrawGraphColors
Colour each shape by its constraint-graph colour instead of its body state.
public bool DrawGraphColors { get; set; }
Property Value
DrawIslands
Sleep islands, as bounding boxes.
public bool DrawIslands { get; set; }
Property Value
DrawJointExtras
Joint limits, targets and the like, drawn on top of the joints.
public bool DrawJointExtras { get; set; }
Property Value
DrawJoints
Joints as lines between their anchors. On by default here, unlike in Box2D.
public bool DrawJoints { get; set; }
Property Value
DrawMass
A marker at each body's centre of mass, with its mass as text.
public bool DrawMass { get; set; }
Property Value
DrawShapes
Every shape, in Box2D's body-state colours. On by default.
public bool DrawShapes { get; set; }
Property Value
DrawString
Where text goes: world position, the text, its colour. Nothing is drawn when unset.
public Action<Vector2, string, Color>? DrawString { get; set; }
Property Value
FillAlpha
Fill intensity of the shapes while the world is drawn, 0 to 1. Defaults to TestbedAlpha, the testbed's look: a bright outline around a dimmed, see-through inside. The batch's own value is put back when the draw is done.
public float FillAlpha { get; set; }
Property Value
ForceScale
Length per unit of force for the force lines.
public float ForceScale { get; set; }
Property Value
JointScale
Size of the joint drawings.
public float JointScale { get; set; }
Property Value
LinePixels
On-screen width of every line, in pixels.
public float LinePixels { get; set; }
Property Value
PointScale
World units per unit of a point's size; Box2D sizes points in screen pixels.
public float PointScale { get; set; }
Property Value
Methods
Draw(B2WorldId)
Submits the whole world to the batch. Call once per frame, after stepping.
public void Draw(B2WorldId world)
Parameters
worldB2WorldId
Draw(Box2DSimulation)
Submits the whole world to the batch. Call once per frame, after stepping.
public void Draw(Box2DSimulation simulation)
Parameters
simulationBox2DSimulation