LittleJS 1.28.0

Box2D

Box2dPlugin

Box2D Global Object

  • Wraps Box2d world and provides global functions

Constructor

new Box2dPlugin(instance)box2d.js:2280

Create the global Box2D plugin object, box2dInit does this

instance Object

Members

Methods

Members

bodyTypeDynamic : numberbox2d.js:2309

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

bodyTypeKinematic : numberbox2d.js:2306

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

bodyTypeStatic : numberbox2d.js:2303

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

instance : Objectbox2d.js:2290

The Box2d instance

objects : Array<Box2dObject>box2d.js:2296

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

positionIterations : numberbox2d.js:2300

Position iterations per update

velocityIterations : numberbox2d.js:2298

Velocity iterations per update

world : Objectbox2d.js:2292

The Box2d world

Methods

boxCast(pos, size, includeSensors) → Box2dObject|undefinedbox2d.js:2501

The first object whose shapes' bounding boxes overlap a box, not the shapes themselves, so near the corner of a turned box or a circle it finds one the box does not touch; use pointCast or a raycast for exact

pos Vector2
size Vector2
includeSensors boolean optional, default false

Also find sensors, trigger zones are passed through by default

boxCastAll(pos, size, includeSensors) → Array<Box2dObject>box2d.js:2470

Every object whose shapes' bounding boxes overlap a box, not the shapes themselves, so near the corner of a turned box or a circle it finds one the box does not touch; use pointCast or a raycast for exact

pos Vector2
size Vector2
includeSensors boolean optional, default false

Also find sensors, trigger zones are passed through by default

castJointObject(o) → Objectbox2d.js:2697

casts a box2d object to a joint type

o Object
Returns
  • The joint as its own Box2D type
castShapeObject(o) → Objectbox2d.js:2677

casts a box2d object to a shape type

o Object
Returns
  • The shape as its own Box2D type
circleCast(pos, diameter, includeSensors) → Box2dObject|undefinedbox2d.js:2548

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

pos Vector2
diameter number
includeSensors boolean optional, default false

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

circleCastAll(pos, diameter, includeSensors) → Array<Box2dObject>box2d.js:2533

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

pos Vector2
diameter number
includeSensors boolean optional, default false

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

drawFixture(fixture, pos, angle, color, lineColor, lineWidth, useWebGL, context)box2d.js:2609

draws a fixture

fixture Object
pos Vector2
angle number
color Color optional
lineColor Color optional
lineWidth number optional, default 0.1
useWebGL boolean optional, default glEnable
context CanvasRenderingContext2D optional
isNull(o) → booleanbox2d.js:2672

checks if a box2d object is null

o Object
pointCast(pos, dynamicOnly, includeSensors) → Box2dObject|undefinedbox2d.js:2568

point cast and return the first object

pos Vector2
dynamicOnly boolean optional, default true
includeSensors boolean optional, default false

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

raycast(start, end, includeSensors) → Box2dRaycastResult|undefinedbox2d.js:2459

raycast and return the first result

start Vector2
end Vector2
includeSensors boolean optional, default false

Also hit sensors, trigger zones are passed through by default

raycastAll(start, end, includeSensors) → Array<Box2dRaycastResult>box2d.js:2423

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

start Vector2
end Vector2
includeSensors boolean optional, default false

Also hit sensors, trigger zones are passed through by default

step(frames)box2d.js:2392

Step the physics world simulation

frames number optional, default 1
vec2dTo(v) → Objectbox2d.js:2663

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

v Vector2
Returns
  • A Box2D vector, its b2Vec2
vec2From(v) → Vector2box2d.js:2644

converts a box2d vec2 to a Vector2

v Object
vec2FromPointer(vp) → Vector2box2d.js:2653

converts a box2d vec2 pointer to a Vector2

vp Object