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

Box2dDistanceJoint
Box2dFrictionJoint
Box2dGearJoint
Box2dJoint
Box2dKinematicObject
Box2dMotorJoint
Box2dObject
Box2dPinJoint
Box2dPlugin
Box2dPrismaticJoint
Box2dPulleyJoint
Box2dRaycastResult
Box2dRevoluteJoint
Box2dRopeJoint
Box2dStaticObject
Box2dTargetJoint
Box2dTileLayer
Box2dWeldJoint
Box2dWheelJoint

Members

(static) box2d :Box2dPlugin

Global Box2d Plugin object

Type:
  • Box2dPlugin

(static) box2dDebug :boolean

Enable Box2D debug drawing

Type:
  • boolean

Methods

(async, static) box2dInit() → {Promise.<Box2dPlugin>}

Box2d Init - Call with await to init box2d

Returns:
Type: 
Promise.<Box2dPlugin>
Example
await box2dInit();
 

(static) box2dSetDebug(enable)

Enable Box2D debug drawing

Parameters:
NameTypeDescription
enableboolean