Class b2DebugDraw

Implement and register this class with a b2World to provide debug drawing of physics entities in your game.

example

Although Box2D is a physics engine and therefore has nothing to do with drawing, Box2dFlash provides such methods for debugging which are defined in the b2DebugDraw class. In Box2dWeb, a b2DebugDraw takes a canvas-context instead of a Sprite:

var debugDraw = new Box2D.Dynamics.b2DebugDraw();
debugDraw.SetSprite(document.GetElementsByTagName("canvas")[0].getContext("2d"));

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(): b2DebugDraw

Constructor.

Returns

b2DebugDraw

Properties

public static e_aabbBit: number

Draw axis aligned bounding boxes.

public static e_centerOfMassBit: number

Draw center of mass frame.

public static e_controllerBit: number

Draw controllers.

public static e_jointBit: number

Draw joint connections.

public static e_pairBit: number

Draw broad-phase pairs.

public static e_shapeBit: number

Draw shapes.

Methods

public AppendFlags(flags: number)

Append flags to the current flags.

Parameters

  • flags: number

    Flags to add.

public ClearFlags(flags: number)

Clear flags from the current flags.

Parameters

  • flags: number

    flags to clear.

public DrawCircle(center: b2Vec2, radius: number, color: b2Color)

Draw a circle.

Parameters

  • center: b2Vec2

    Circle center point.

  • radius: number

    Circle radius.

  • color: b2Color

    Circle draw color.

public DrawPolygon(vertices: b2Vec2[], vertexCount: number, color: b2Color)

Draw a closed polygon provided in CCW order.

Parameters

  • vertices: b2Vec2[]

    Polygon verticies.

  • vertexCount: number

    Number of vertices in the polygon, usually vertices.length.

  • color: b2Color

    Polygon draw color.

public DrawSegment(p1: b2Vec2, p2: b2Vec2, color: b2Color)

Draw a line segment.

Parameters

public DrawSolidCircle(center: b2Vec2, radius: number, axis: b2Vec2, color: b2Color)

Draw a solid circle.

Parameters

  • center: b2Vec2

    Circle center point.

  • radius: number

    Circle radius.

  • axis: b2Vec2

    Circle axis.

  • color: b2Color

    Circle color.

public DrawSolidPolygon(vertices: b2Vec2[], vertexCount: number, color: b2Color)

Draw a solid closed polygon provided in CCW order.

Parameters

  • vertices: b2Vec2[]

    Polygon verticies.

  • vertexCount: number

    Number of vertices in the polygon, usually vertices.length.

  • color: b2Color

    Polygon draw color.

public DrawTransform(xf: b2Transform)

Draw a transform. Choose your own length scale.

Parameters

public GetAlpha(): number

Get the alpha value used for lines.

Returns

number

Alpha value used for drawing lines.

public GetDrawScale(): number

Get the draw scale.

Returns

number

Draw scale ratio.

public GetFillAlpha(): number

Get the alpha value used for fills.

Returns

number

Alpha value used for drawing fills.

public GetFlags(): number

Get the drawing flags.

Returns

number

Drawing flags.

public GetLineThickness(): number

Get the line thickness.

Returns

number

Line thickness.

public GetSprite(): CanvasRenderingContext2D

Get the HTML Canvas Element for drawing.

note

box2dflash uses Sprite object, box2dweb uses CanvasRenderingContext2D, that is why this function is called GetSprite().

Returns

CanvasRenderingContext2D

The HTML Canvas Element used for debug drawing.

public GetXFormScale(): number

Get the scale used for drawing XForms.

Returns

number

Scale for drawing transforms.

public SetAlpha(alpha: number)

Set the alpha value used for lines.

Parameters

  • alpha: number

    Alpha value for drawing lines.

public SetDrawScale(drawScale: number)

Set the draw scale.

Parameters

  • drawScale: number

    Draw scale ratio.

public SetFillAlpha(alpha: number)

Set the alpha value used for fills.

Parameters

  • alpha: number

    Alpha value for drawing fills.

public SetFlags(flags: number)

Set the drawing flags.

Parameters

  • flags: number

    Sets the drawing flags.

public SetLineThickness(lineThickness: number)

Set the line thickness.

Parameters

  • lineThickness: number

    The new line thickness.

public SetSprite(canvas: CanvasRenderingContext2D)

Set the HTML Canvas Element for drawing.

note

box2dflash uses Sprite object, box2dweb uses CanvasRenderingContext2D, that is why this function is called SetSprite().

Parameters

  • canvas: CanvasRenderingContext2D

    HTML Canvas Element to draw debug information to.

public SetXFormScale(xformScale: number)

Set the scale used for drawing XForms.

Parameters

  • xformScale: number

    The transform scale.