LittleJS 1.30.1

Box2D

Box2dPlugin

Box2D Global Object

  • Wraps Box2d world and provides global functions

Constructor

new Box2dPlugin(instance)box2d.js:2338

Create the global Box2D plugin object, box2dInit does this

instance Box2dModule

Members

Methods

Members

bodyTypeDynamic : numberbox2d.js:2369

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

bodyTypeKinematic : numberbox2d.js:2366

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

bodyTypeStatic : numberbox2d.js:2363

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

The Box2d instance

objects : Array<Box2dObject>box2d.js:2356

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

positionIterations : numberbox2d.js:2360

Position iterations per update

velocityIterations : numberbox2d.js:2358

Velocity iterations per update

The Box2d world

Methods

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

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:2530

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) → b2Jointbox2d.js:2757

casts a box2d object to a joint type

o b2Joint
Returns
  • The joint as its own Box2D type
castShapeObject(o) → b2Shapebox2d.js:2737

casts a box2d object to a shape type

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

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:2593

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:2669

draws a fixture

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

checks if a box2d object is null

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

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:2519

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:2483

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:2452

Step the physics world simulation

frames number optional, default 1
vec2dTo(v) → b2Vec2box2d.js:2723

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
vec2From(v) → Vector2box2d.js:2704

converts a box2d vec2 to a Vector2

v b2Vec2
vec2FromPointer(vp) → Vector2box2d.js:2713

converts a box2d vec2 pointer to a Vector2

vp number