Table of Contents

Class Box2DDebugDraw

Namespace
Stride.CommunityToolkit.Box2D
Assembly
Stride.CommunityToolkit.Box2D.dll

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

batch ShapeBatch

Properties

DrawBodyNames

Body names, through DrawString.

public bool DrawBodyNames { get; set; }

Property Value

bool

DrawBounds

Axis-aligned bounding boxes of every shape.

public bool DrawBounds { get; set; }

Property Value

bool

DrawContactFeatures

Contact feature ids as text.

public bool DrawContactFeatures { get; set; }

Property Value

bool

DrawContactForces

Contact normal impulses, as lines scaled by ForceScale.

public bool DrawContactForces { get; set; }

Property Value

bool

DrawContactNormals

Contact normals.

public bool DrawContactNormals { get; set; }

Property Value

bool

DrawContactPoints

Contact points.

public bool DrawContactPoints { get; set; }

Property Value

bool

DrawFrictionForces

Contact friction impulses, as lines scaled by ForceScale.

public bool DrawFrictionForces { get; set; }

Property Value

bool

DrawGraphColors

Colour each shape by its constraint-graph colour instead of its body state.

public bool DrawGraphColors { get; set; }

Property Value

bool

DrawIslands

Sleep islands, as bounding boxes.

public bool DrawIslands { get; set; }

Property Value

bool

DrawJointExtras

Joint limits, targets and the like, drawn on top of the joints.

public bool DrawJointExtras { get; set; }

Property Value

bool

DrawJoints

Joints as lines between their anchors. On by default here, unlike in Box2D.

public bool DrawJoints { get; set; }

Property Value

bool

DrawMass

A marker at each body's centre of mass, with its mass as text.

public bool DrawMass { get; set; }

Property Value

bool

DrawShapes

Every shape, in Box2D's body-state colours. On by default.

public bool DrawShapes { get; set; }

Property Value

bool

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

Action<Vector2, string, Color>

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

float

ForceScale

Length per unit of force for the force lines.

public float ForceScale { get; set; }

Property Value

float

JointScale

Size of the joint drawings.

public float JointScale { get; set; }

Property Value

float

LinePixels

On-screen width of every line, in pixels.

public float LinePixels { get; set; }

Property Value

float

PointScale

World units per unit of a point's size; Box2D sizes points in screen pixels.

public float PointScale { get; set; }

Property Value

float

Methods

Draw(B2WorldId)

Submits the whole world to the batch. Call once per frame, after stepping.

public void Draw(B2WorldId world)

Parameters

world B2WorldId

Draw(Box2DSimulation)

Submits the whole world to the batch. Call once per frame, after stepping.

public void Draw(Box2DSimulation simulation)

Parameters

simulation Box2DSimulation