new Box2dObject(pos, size, tileInfo, angle, color, bodyType, renderOrder)box2d.js:415Create 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:415Create a LittleJS object with Box2d physics
body : b2Bodybox2d.js:438The Box2d body, undefined once it is destroyed
edgeListFixtures : Map<number, Array<Vector2>>box2d.js:452edgeLists : Array<Array<Vector2>>box2d.js:446List of all edges for default box2d drawing
edgeLoops : Array<Array<Vector2>>box2d.js:449List of all edge loops for default box2d drawing
lineColor : Colorbox2d.js:441Line color used for default box2d drawing
lineWidth : numberbox2d.js:443Line width used for default box2d drawing
surfaceSpeed : numberbox2d.js:456How 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) → b2Fixture|undefinedbox2d.js:630Add 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) → b2Fixture|undefinedbox2d.js:745Add 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) → b2Fixturebox2d.js:767Add an edge shape to the body
point1 Vector2point2 Vector2density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdEdgeList(points, density, friction, restitution, isSensor) → Array<b2Fixture>box2d.js:786Add an edge list to the body
points Array<Vector2>density number optionalfriction number optionalrestitution number optionalisSensor boolean optionaladdEdgeLoop(points, density, friction, restitution, isSensor) → Array<b2Fixture>box2d.js:820Add 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) → b2Fixture|undefinedbox2d.js:656Add 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) → b2Fixture|undefinedbox2d.js:725Add 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) → b2Fixture|undefinedbox2d.js:704Add 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) → b2Fixturebox2d.js:600Add a shape fixture to the body
shape b2Shapedensity number optional, default 1friction number optional, default 0.2restitution number optional, default 0isSensor boolean optional, default falseapplyAcceleration(acceleration, pos)box2d.js:1135Apply 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:1165Apply angular acceleration to this object (changes angular velocity by acceleration, mass-independent, clockwise — matches EngineObject.applyAngularAcceleration).
acceleration numberapplyAngularImpulse(impulse)box2d.js:1177Apply an instantaneous angular impulse. Changes angular velocity by impulse / inertia immediately, clockwise like angle.
impulse numberapplyImpulse(impulse, pos)box2d.js:1147Apply 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:561Called when a contact begins, while the world steps: a destroy, and a setter that moves a body or changes its type or mass, waits until the step is done, and creating objects, fixtures or joints must wait until after the step
otherObject Box2dObjectfixture b2Fixture optionalThis object's fixture that touched
otherFixture b2Fixture 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:467Destroy this object and its physics body
immediate boolean optional, default falseRemove it now, as EngineObject.destroy does, children included
destroyAllFixtures()box2d.js:868Destroy all fixtures from the body, from a contact callback once the step is done
destroyFixture(fixture)box2d.js:848Destroy a fixture from the body, from a contact callback once the step is done
fixture b2FixturedrawFixtures(color, lineColor, lineWidth, useWebGL, context)box2d.js:526Draw all this object's fixtures
endContact(otherObject, fixture, otherFixture)box2d.js:569Called when a contact ends, while the world steps or a body is destroyed: a destroy, and a setter that moves a body or changes its type or mass, waits until the step is done, and creating objects, fixtures or joints must wait until after the step
otherObject Box2dObjectfixture b2Fixture optionalThis object's fixture that touched
otherFixture b2Fixture optionalThe other object's fixture that touched
getAngularVelocity() → numberbox2d.js:897Gets the angular velocity, clockwise like angle
getBodyType() → numberbox2d.js:918Gets the physics body type
getCenterOfMass() → Vector2box2d.js:889Gets the center of mass in world space
getFixtureList() → Array<b2Fixture>box2d.js:1192Get list of fixtures for this object
getInertia() → numberbox2d.js:905Gets the rotational inertia about the center of mass
getIsAwake() → booleanbox2d.js:914Check if this object is awake
getJointList() → Array<(Box2dJoint|b2Joint)>box2d.js:1210Get 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:893Gets the linear velocity
getMass() → numberbox2d.js:901Gets the mass
getSpeed() → numberbox2d.js:922Get the speed of this object
getVelocityAtPoint(pos) → Vector2box2d.js:928Get 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:1188Check if this object has any fixtures
hasJoints() → booleanbox2d.js:1205Check if this object has any joints
preSolve(otherObject, fixture, otherFixture, contact)box2d.js:588Called 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 b2Fixture optionalThis object's fixture that touches
otherFixture b2Fixture 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:502Render the object, uses box2d drawing if no tile info exists
renderDebugInfo()box2d.js:512Draw its fixtures for the debug view: yellow asleep, blue static, both when both
resetMassData()box2d.js:1055Reset the mass, center of mass, and moment, from a contact callback once the step is done
setAngle(angle)box2d.js:966Sets 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:996Sets 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:984Sets the angular velocity, clockwise like angle
angularVelocity numbersetBodyType(type)box2d.js:1026Set the physics body type, from a contact callback it changes once the step is done
type numbersetBullet(isBullet)box2d.js:1018Should be like a bullet for continuous collision detection?
isBullet boolean optional, default truesetFilterData(categoryBits, ignoreCategoryBits, groupIndex)box2d.js:1096Set 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:1035Set whether the body can rotate
isFixed boolean optional, default truesetLinearDamping(damping)box2d.js:990Sets 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:1063Set 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:1051Set the moment of inertia of the body, about its center of mass
momentOfInertia numbersetPosition(pos)box2d.js:952Sets 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:1030Set whether the body is allowed to sleep
isAllowed boolean optional, default truesetSurfaceSpeed(speed)box2d.js:1009Sets how fast its surface moves, clockwise around it, like a conveyor belt, see surfaceSpeed
speed numberWorld units per second
setTransform(pos, angle)box2d.js:936Sets the position and angle, from a contact callback the body moves once the step is done
pos Vector2angle numberupdatePhysics()box2d.js:490Box2d objects updated with Box2d world step
updateTransforms(updateChildren)box2d.js:495Update 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