new Box2dObject(pos, size, tileInfo, angle, color, bodyType, renderOrder)box2d.js:383Create a LittleJS object with Box2d physics
Box2D Object - extend with your own custom physics objects
Extends EngineObject
Extended by Box2dKinematicObject, Box2dStaticObject
new Box2dObject(pos, size, tileInfo, angle, color, bodyType, renderOrder)box2d.js:383Create a LittleJS object with Box2d physics
body : Objectbox2d.js:405The Box2d body, undefined once it is destroyed
edgeLists : Array<Array<Vector2>>box2d.js:413List of all edges for default box2d drawing
edgeLoops : Array<Array<Vector2>>box2d.js:416List of all edge loops for default box2d drawing
lineColor : Colorbox2d.js:408Line color used for default box2d drawing
lineWidth : numberbox2d.js:410Line width used for default box2d drawing
surfaceSpeed : numberbox2d.js:422How fast its surface moves, clockwise around it, in world units per second, like a conveyor belt: what touches it is carried along by friction, to the right across its top when positive; set it with setSurfaceSpeed, which wakes what rests on it
addBox(size, offset, angle, density, friction, restitution, isSensor) → Object|undefinedbox2d.js:594Add a box shape to the body
size Vector2 optionaloffset Vector2 optionalangle number optional, default 0LittleJS convention (clockwise positive). Negated internally to match Box2D's CCW-positive convention so the fixture aligns with the same angle passed to drawRect/drawTile.
density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdCircle(diameter, offset, density, friction, restitution, isSensor) → Object|undefinedbox2d.js:709Add a circle shape to the body
diameter number optional, default 1offset Vector2 optionaldensity number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdEdge(point1, point2, density, friction, restitution, isSensor) → Objectbox2d.js:731Add an edge shape to the body
point1 Vector2point2 Vector2density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdEdgeList(points, density, friction, restitution, isSensor) → Array<Object>box2d.js:750Add an edge list to the body
points Array<Vector2>density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdEdgeLoop(points, density, friction, restitution, isSensor) → Array<Object>box2d.js:784Add an edge loop to the body, an edge loop connects the end points
points Array<Vector2>density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdPoly(points, density, friction, restitution, isSensor) → Object|undefinedbox2d.js:620Add a polygon shape to the body, the convex hull of its points; Box2D takes 3 to 8 points, not all in a line, and no fixture is made from any other; points closer than .001 count as one
points Array<Vector2>density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdRandomPoly(diameter, density, friction, restitution, isSensor) → Object|undefinedbox2d.js:689Add a random polygon shape to the body
diameter number optional, default 1density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdRegularPoly(diameter, sides, density, friction, restitution, isSensor) → Object|undefinedbox2d.js:668Add a regular polygon shape to the body
diameter number optional, default 1sides number optional, default 83 to 8, the most Box2D polygons have
density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdShape(shape, density, friction, restitution, isSensor) → Objectbox2d.js:564Add a shape fixture to the body
shape Objectdensity number optional, default 1friction number optional, default 0.2restitution number optional, default 0isSensor boolean optional, default falseapplyAcceleration(acceleration, pos)box2d.js:1099Apply acceleration to this object (changes velocity by acceleration, mass-independent like EngineObject.applyAcceleration, but in units per second). Use applyImpulse if you want the mass-dependent velocity change Δv = impulse / mass, or applyForce for a Newton-style sustained force.
applyAngularAcceleration(acceleration)box2d.js:1129Apply angular acceleration to this object (changes angular velocity by acceleration, mass-independent, clockwise — matches EngineObject.applyAngularAcceleration).
acceleration numberapplyAngularImpulse(impulse)box2d.js:1141Apply an instantaneous angular impulse. Changes angular velocity by impulse / inertia immediately, clockwise like angle.
impulse numberapplyImpulse(impulse, pos)box2d.js:1111Apply an instantaneous linear impulse. Changes velocity immediately by impulse / mass (so heavier bodies move less for the same impulse).
beginContact(otherObject, fixture, otherFixture, impactSpeed, contact)box2d.js:526Called when a contact begins, while the world steps: a destroy or a setter waits until the step is done, and creating objects, fixtures or joints must wait until after the step
otherObject Box2dObjectfixture Object optionalThis object's fixture that touched
otherFixture Object optionalThe other object's fixture that touched
impactSpeed number optionalHow fast they were closing as they touched
contact Box2dContact optionalWhere they touched and how hard they hit
destroy(immediate)box2d.js:433Destroy this object and its physics body
immediate boolean optional, default falseRemove it now, as EngineObject.destroy does, children included
destroyAllFixtures()box2d.js:832Destroy all fixtures from the body, from a contact callback once the step is done
destroyFixture(fixture)box2d.js:812Destroy a fixture from the body, from a contact callback once the step is done
fixture ObjectdrawFixtures(color, lineColor, lineWidth, useWebGL, context)box2d.js:492Draw all this object's fixtures
endContact(otherObject, fixture, otherFixture)box2d.js:533Called when a contact ends, while the world steps or a body is destroyed: a destroy or a setter waits until the step is done, and creating objects, fixtures or joints must wait until after the step
otherObject Box2dObjectfixture Object optionalThis object's fixture that touched
otherFixture Object optionalThe other object's fixture that touched
getAngularVelocity() → numberbox2d.js:861Gets the angular velocity, clockwise like angle
getBodyType() → numberbox2d.js:882Gets the physics body type
getCenterOfMass() → Vector2box2d.js:853Gets the center of mass in world space
getFixtureList() → Array<Object>box2d.js:1156Get list of fixtures for this object
getInertia() → numberbox2d.js:869Gets the rotational inertia about the center of mass
getIsAwake() → booleanbox2d.js:878Check if this object is awake
getJointList() → Array<(Box2dJoint|Object)>box2d.js:1174Get list of joints for this object, the Box2dJoint for each one made through LittleJS, and the Box2D joint, cast to its type, for any made on the world directly
getLinearVelocity() → Vector2box2d.js:857Gets the linear velocity
getMass() → numberbox2d.js:865Gets the mass
getSpeed() → numberbox2d.js:886Get the speed of this object
getVelocityAtPoint(pos) → Vector2box2d.js:892Get the velocity of a point on this object, its linear velocity and its spin about its center of mass together, in Box2D's units like getLinearVelocity
pos Vector2the point in world space
hasFixtures() → booleanbox2d.js:1152Check if this object has any fixtures
hasJoints() → booleanbox2d.js:1169Check if this object has any joints
preSolve(otherObject, fixture, otherFixture, contact)box2d.js:552Called before Box2D solves a contact, each step while they touch, for an object that overrides it, while the world steps as beginContact is; change the contact to change how they collide
otherObject Box2dObjectfixture Object optionalThis object's fixture that touches
otherFixture Object optionalThe other object's fixture that touches
contact Box2dPreSolveContact optionalWhere they touch and how they collide
// drop down through a one way platform
player.preSolve = (other, fixture, otherFixture, contact)=>
{
if (other.oneWay && keyIsDown('ArrowDown'))
contact.enabled = false;
}render()box2d.js:468Render the object, uses box2d drawing if no tile info exists
renderDebugInfo()box2d.js:478Draw its fixtures for the debug view: yellow asleep, blue static, both when both
resetMassData()box2d.js:1019Reset the mass, center of mass, and moment, from a contact callback once the step is done
setAngle(angle)box2d.js:930Sets the angle, from a contact callback the body turns once the step is done, keeping the position it has then
angle numbersetAngularDamping(damping)box2d.js:960Sets the angular damping, Box2D's: a rate, 0 none and larger slows its turning faster, with no upper limit; angleDamping does nothing on a Box2dObject
damping numbersetAngularVelocity(angularVelocity)box2d.js:948Sets the angular velocity, clockwise like angle
angularVelocity numbersetBodyType(type)box2d.js:990Set the physics body type, from a contact callback it changes once the step is done
type numbersetBullet(isBullet)box2d.js:982Should be like a bullet for continuous collision detection?
isBullet boolean optional, default truesetFilterData(categoryBits, ignoreCategoryBits, groupIndex)box2d.js:1060Set the collision filter data for the fixtures this body has now, a fixture added later has the default filter, category 1 colliding with everything
categoryBits number optional, default 1ignoreCategoryBits number optional, default 0groupIndex number optional, default 0setFixedRotation(isFixed)box2d.js:999Set whether the body can rotate
isFixed boolean optional, default truesetLinearDamping(damping)box2d.js:954Sets the linear damping, Box2D's: a rate, 0 none and larger slows it faster, with no upper limit, where the damping of an EngineObject is the fraction it keeps each frame and does nothing on a Box2dObject
damping numbersetMassData(localCenter, mass, momentOfInertia)box2d.js:1027Set the mass data of the body, from a contact callback once the step is done; a mass of 0 or less becomes 1, use setBodyType for a static body; call it after adding fixtures and after setFixedRotation, both of which put the mass back to what the fixtures give
localCenter Vector2 optionalmass number optionalmomentOfInertia number optionalAbout the center of mass
setMomentOfInertia(momentOfInertia)box2d.js:1015Set the moment of inertia of the body, about its center of mass
momentOfInertia numbersetPosition(pos)box2d.js:916Sets the position, from a contact callback the body moves once the step is done, keeping the angle it has then
pos Vector2setSleepingAllowed(isAllowed)box2d.js:994Set whether the body is allowed to sleep
isAllowed boolean optional, default truesetSurfaceSpeed(speed)box2d.js:973Sets how fast its surface moves, clockwise around it, like a conveyor belt, see surfaceSpeed
speed numberWorld units per second
setTransform(pos, angle)box2d.js:900Sets the position and angle, from a contact callback the body moves once the step is done
pos Vector2angle numberupdatePhysics()box2d.js:456Box2d objects updated with Box2d world step
updateTransforms(updateChildren)box2d.js:461Update the object transform, called automatically by engine even when paused; its body places it, so it can be a parent but not a child, connect it to another with a joint
updateChildren boolean optional, default trueAlso update the children's transforms