LittleJS 1.30.1

Box2D

LittleJS Box2D Physics Plugin

  • Box2dObject extends EngineObject with Box2D physics
  • Call box2dInit() to enable
  • You will also need to include box2d.wasm.js
  • Uses a super fast web assembly port of Box2D v2.3.1
  • More info: https://github.com/kripken/box2d.js
  • Functions to create polygon, circle, and edge shapes
  • Contact begin and end callbacks
  • Wraps b2Vec2 type to/from Vector2
  • Raycasting and querying
  • Box2dTileLayer for grid based collision
  • Every type of joint
  • Debug physics drawing
  • Box2D works per second: its velocities and accelerations are in units per second, and it reads the engine's gravity as units per second squared, where an EngineObject's are per frame

Classes

Functions

Members

Typedefs

Functions

box2dInit() → Promise<Box2dPlugin>asyncbox2d.js:2798

Box2d Init - Call with await to init box2d

await box2dInit();
box2dSetDebug(enable)box2d.js:337

Enable Box2D debug drawing

enable boolean

Members

Global Box2d Plugin object

box2dDebug : boolean default falsebox2d.js:31

Enable Box2D debug drawing

Typedefs

b2Body : anybox2d.js:41

A Box2D body; box2d.js has no types, so it is any, named for what it is

b2Fixture : anybox2d.js:45

A Box2D fixture, a shape attached to a body; box2d.js has no types, so it is any, named for what it is

b2Joint : anybox2d.js:53

A Box2D joint; box2d.js has no types, so it is any, named for what it is

b2JointDef : anybox2d.js:57

A Box2D joint definition, what a joint is made from; box2d.js has no types, so it is any, named for what it is

b2Shape : anybox2d.js:49

A Box2D shape: b2CircleShape, b2EdgeShape, b2PolygonShape or b2ChainShape; box2d.js has no types, so it is any, named for what it is

b2Vec2 : anybox2d.js:61

A Box2D vector; box2d.js has no types, so it is any, named for what it is

b2World : anybox2d.js:37

A Box2D world; box2d.js has no types, so it is any, named for what it is

Box2dContact : Objectbox2d.js:82

Where and how hard two objects hit, given to beginContact

point Vector2|undefined

Where they touched in world space, between the two points of a flat landing, toward the one pushed harder; undefined for a sensor

normal Vector2|undefined

The other object's surface normal where they touched, pointing toward this object; undefined for a sensor

impulse number

An estimate of how hard they hit: the impulse that stops them closing, from the mass and inertia of both where they touched, times 1 + restitution; mass times world units per second, 0 for a sensor

Box2dModule : anybox2d.js:33

The box2d.js module, what Box2D() gives and box2d.instance holds; box2d.js has no types, so it is any, named for what it is

Box2dPreSolveContact : Objectbox2d.js:152

A contact about to be solved, given to preSolve, whose changes the solver takes

point Vector2

Where they touch in world space, between the points when there are two

normal Vector2

The other object's surface normal where they touch, pointing toward this object

enabled boolean

Set false to let them pass through each other until they stop touching, true to make them collide again

friction number

The contact's friction, kept while they touch

restitution number

The contact's restitution, kept while they touch

surfaceSpeed number

How fast this object's surface moves there for this step, clockwise around it, its surfaceSpeed to start with