Box2D. Box2dPlugin

Box2D Global Object

  • Wraps Box2d world and provides global functions

Constructor

new Box2dPlugin(instance)

Create the global Box2D plugin object, box2dInit does this

Parameters:
NameTypeDescription
instanceObject

Members

bodyTypeDynamic :number

Type:
  • number
Properties
TypeDescription
number

Dynamic, positive mass, non-zero velocity determined by forces, moved by solver

bodyTypeKinematic :number

Type:
  • number
Properties
TypeDescription
number

Kinematic, zero mass, non-zero velocity set by user, moved by solver

bodyTypeStatic :number

Type:
  • number
Properties
TypeDescription
number

Static, zero mass, zero velocity, may be manually moved

instance

Properties
TypeDescription
Object

The Box2d instance

objects :Array.<Box2dObject>

Type:
  • Array.<Box2dObject>
Properties
TypeDescription
Array.<Box2dObject>

List of all Box2d objects, a destroyed one stays until the next step with its body undefined

positionIterations

Properties
TypeDescription
number

Position iterations per update

velocityIterations

Properties
TypeDescription
number

Velocity iterations per update

world

Properties
TypeDescription
Object

The Box2d world

Methods

boxCast(pos, size, includeSensorsopt) → {Box2dObject|undefined}

box aabb cast and return the first object

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2
includeSensorsboolean<optional>
false

Also find sensors, trigger zones are passed through by default

Returns:
Type: 
Box2dObject | undefined

boxCastAll(pos, size, includeSensorsopt) → {Array.<Box2dObject>}

box aabb cast and return all the objects

Parameters:
NameTypeAttributesDefaultDescription
posVector2
sizeVector2
includeSensorsboolean<optional>
false

Also find sensors, trigger zones are passed through by default

Returns:
Type: 
Array.<Box2dObject>

castJointObject(o)

casts a box2d object to a joint type

Parameters:
NameTypeDescription
oObject

castShapeObject(o)

casts a box2d object to a shape type

Parameters:
NameTypeDescription
oObject

circleCast(pos, diameter, includeSensorsopt) → {Box2dObject|undefined}

circle cast and return the object whose position is nearest, of those within the circle

Parameters:
NameTypeAttributesDefaultDescription
posVector2
diameternumber
includeSensorsboolean<optional>
false

Also find objects whose shapes are all sensors, like trigger zones

Returns:
Type: 
Box2dObject | undefined

circleCastAll(pos, diameter, includeSensorsopt) → {Array.<Box2dObject>}

circle cast and return all the objects whose position is within the circle, wherever their shapes are

Parameters:
NameTypeAttributesDefaultDescription
posVector2
diameternumber
includeSensorsboolean<optional>
false

Also find objects whose shapes are all sensors, like trigger zones

Returns:
Type: 
Array.<Box2dObject>

drawFixture(fixture, pos, angle, coloropt, lineColoropt, lineWidthopt, useWebGLopt, contextopt)

draws a fixture

Parameters:
NameTypeAttributesDefaultDescription
fixtureObject
posVector2
anglenumber
colorColor<optional>
lineColorColor<optional>
lineWidthnumber<optional>
0.1
useWebGLboolean<optional>
glEnable
contextCanvasRenderingContext2D<optional>

isNull(o)

checks if a box2d object is null

Parameters:
NameTypeDescription
oObject

pointCast(pos, dynamicOnlyopt, includeSensorsopt) → {Box2dObject|undefined}

point cast and return the first object

Parameters:
NameTypeAttributesDefaultDescription
posVector2
dynamicOnlyboolean<optional>
true
includeSensorsboolean<optional>
false

Also find sensors, so a pickup radius does not grab its object from afar

Returns:
Type: 
Box2dObject | undefined

raycast(start, end, includeSensorsopt) → {Box2dRaycastResult|undefined}

raycast and return the first result

Parameters:
NameTypeAttributesDefaultDescription
startVector2
endVector2
includeSensorsboolean<optional>
false

Also hit sensors, trigger zones are passed through by default

Returns:
Type: 
Box2dRaycastResult | undefined

raycastAll(start, end, includeSensorsopt) → {Array.<Box2dRaycastResult>}

raycast and return a list of all the results, nearest first

Parameters:
NameTypeAttributesDefaultDescription
startVector2
endVector2
includeSensorsboolean<optional>
false

Also hit sensors, trigger zones are passed through by default

Returns:
Type: 
Array.<Box2dRaycastResult>

step(framesopt)

Step the physics world simulation

Parameters:
NameTypeAttributesDefaultDescription
framesnumber<optional>
1

vec2From(v)

converts a box2d vec2 to a Vector2

Parameters:
NameTypeDescription
vObject

vec2FromPointer(vp)

converts a box2d vec2 pointer to a Vector2

Parameters:
NameTypeDescription
vpObject

vec2dTo(v)

converts a Vector2 to a new box2d vec2, which stays until destroyed with box2d.instance.destroy; the plugin itself passes Box2D reused ones, since Box2D copies every vector it is given

Parameters:
NameTypeDescription
vVector2