Constructor
new Box2dPlugin(instance)
Create the global Box2D plugin object, box2dInit does this
| Name | Type | Description |
|---|---|---|
instance | Object |
- Source
Members
bodyTypeDynamic :number
- number
| Type | Description |
|---|---|
| number | Dynamic, positive mass, non-zero velocity determined by forces, moved by solver |
- Source
bodyTypeKinematic :number
- number
| Type | Description |
|---|---|
| number | Kinematic, zero mass, non-zero velocity set by user, moved by solver |
- Source
bodyTypeStatic :number
- number
| Type | Description |
|---|---|
| number | Static, zero mass, zero velocity, may be manually moved |
- Source
instance
Properties| Type | Description |
|---|---|
| Object | The Box2d instance |
- Source
objects :Array.<Box2dObject>
- Array.<Box2dObject>
| Type | Description |
|---|---|
| Array.<Box2dObject> | List of all Box2d objects, a destroyed one stays until the next step with its body undefined |
- Source
positionIterations
Properties| Type | Description |
|---|---|
| number | Position iterations per update |
- Source
velocityIterations
Properties| Type | Description |
|---|---|
| number | Velocity iterations per update |
- Source
world
Properties| Type | Description |
|---|---|
| Object | The Box2d world |
- Source
Methods
boxCast(pos, size, includeSensorsopt) → {Box2dObject|undefined}
box aabb cast and return the first object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | |||
includeSensors | boolean | <optional> | false | Also find sensors, trigger zones are passed through by default |
- Source
- Type:
- Box2dObject |
undefined
boxCastAll(pos, size, includeSensorsopt) → {Array.<Box2dObject>}
box aabb cast and return all the objects
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
size | Vector2 | |||
includeSensors | boolean | <optional> | false | Also find sensors, trigger zones are passed through by default |
- Source
- Type:
- Array.<Box2dObject>
castJointObject(o)
casts a box2d object to a joint type
| Name | Type | Description |
|---|---|---|
o | Object |
- Source
castShapeObject(o)
casts a box2d object to a shape type
| Name | Type | Description |
|---|---|---|
o | Object |
- Source
circleCast(pos, diameter, includeSensorsopt) → {Box2dObject|undefined}
circle cast and return the object whose position is nearest, of those within the circle
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
diameter | number | |||
includeSensors | boolean | <optional> | false | Also find objects whose shapes are all sensors, like trigger zones |
- Source
- 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
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
diameter | number | |||
includeSensors | boolean | <optional> | false | Also find objects whose shapes are all sensors, like trigger zones |
- Source
- Type:
- Array.<Box2dObject>
drawFixture(fixture, pos, angle, coloropt, lineColoropt, lineWidthopt, useWebGLopt, contextopt)
draws a fixture
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
fixture | Object | |||
pos | Vector2 | |||
angle | number | |||
color | Color | <optional> | ||
lineColor | Color | <optional> | ||
lineWidth | number | <optional> | 0.1 | |
useWebGL | boolean | <optional> | glEnable | |
context | CanvasRenderingContext2D | <optional> |
- Source
isNull(o)
checks if a box2d object is null
| Name | Type | Description |
|---|---|---|
o | Object |
- Source
pointCast(pos, dynamicOnlyopt, includeSensorsopt) → {Box2dObject|undefined}
point cast and return the first object
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
pos | Vector2 | |||
dynamicOnly | boolean | <optional> | true | |
includeSensors | boolean | <optional> | false | Also find sensors, so a pickup radius does not grab its object from afar |
- Source
- Type:
- Box2dObject |
undefined
raycast(start, end, includeSensorsopt) → {Box2dRaycastResult|undefined}
raycast and return the first result
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
start | Vector2 | |||
end | Vector2 | |||
includeSensors | boolean | <optional> | false | Also hit sensors, trigger zones are passed through by default |
- Source
- Type:
- Box2dRaycastResult |
undefined
raycastAll(start, end, includeSensorsopt) → {Array.<Box2dRaycastResult>}
raycast and return a list of all the results, nearest first
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
start | Vector2 | |||
end | Vector2 | |||
includeSensors | boolean | <optional> | false | Also hit sensors, trigger zones are passed through by default |
- Source
- Type:
- Array.<Box2dRaycastResult>
step(framesopt)
Step the physics world simulation
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
frames | number | <optional> | 1 |
- Source
vec2From(v)
converts a box2d vec2 to a Vector2
| Name | Type | Description |
|---|---|---|
v | Object |
- Source
vec2FromPointer(vp)
converts a box2d vec2 pointer to a Vector2
| Name | Type | Description |
|---|---|---|
vp | Object |
- Source
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
| Name | Type | Description |
|---|---|---|
v | Vector2 |
- Source