Constructor
new Box2dObject(posopt, sizeopt, tileInfoopt, angleopt, coloropt, bodyTypeopt, renderOrderopt)
Create a LittleJS object with Box2d physics
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pos | Vector2 | <optional> | ||
size | Vector2 | <optional> | ||
tileInfo | TileInfo | <optional> | ||
angle | number | <optional> | 0 | |
color | Color | <optional> | ||
bodyType | number | <optional> | ||
renderOrder | number | <optional> | 0 |
- Source
Extends
- EngineObject
Methods
addBox(sizeopt, offsetopt, angleopt, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a box shape to the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
size | Vector2 | <optional> | ||
offset | Vector2 | <optional> | ||
angle | number | <optional> | 0 | |
density | number | <optional> | ||
friction | number | <optional> | ||
restitution | number | <optional> | ||
isSensor | boolean | <optional> |
- Source
addCircle(diameteropt, offsetopt, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a circle shape to the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
diameter | number | <optional> | 1 | |
offset | Vector2 | <optional> | ||
density | number | <optional> | ||
friction | number | <optional> | ||
restitution | number | <optional> | ||
isSensor | boolean | <optional> |
- Source
addEdge(point1, point2, densityopt, frictionopt, restitutionopt, isSensoropt)
Add an edge shape to the body
Name | Type | Attributes | Description |
---|---|---|---|
point1 | Vector2 | ||
point2 | Vector2 | ||
density | number | <optional> | |
friction | number | <optional> | |
restitution | number | <optional> | |
isSensor | boolean | <optional> |
- Source
addEdgeList(points, densityopt, frictionopt, restitutionopt, isSensoropt)
Add an edge list to the body
Name | Type | Attributes | Description |
---|---|---|---|
points | Array.<Vector2> | ||
density | number | <optional> | |
friction | number | <optional> | |
restitution | number | <optional> | |
isSensor | boolean | <optional> |
- Source
addEdgeLoop(points, densityopt, frictionopt, restitutionopt, isSensoropt)
Add an edge loop to the body, an edge loop connects the end points
Name | Type | Attributes | Description |
---|---|---|---|
points | Array.<Vector2> | ||
density | number | <optional> | |
friction | number | <optional> | |
restitution | number | <optional> | |
isSensor | boolean | <optional> |
- Source
addPoly(points, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a polygon shape to the body
Name | Type | Attributes | Description |
---|---|---|---|
points | Array.<Vector2> | ||
density | number | <optional> | |
friction | number | <optional> | |
restitution | number | <optional> | |
isSensor | boolean | <optional> |
- Source
addRandomPoly(diameteropt, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a random polygon shape to the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
diameter | number | <optional> | 1 | |
density | number | <optional> | ||
friction | number | <optional> | ||
restitution | number | <optional> | ||
isSensor | boolean | <optional> |
- Source
addRegularPoly(diameteropt, sidesopt, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a regular polygon shape to the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
diameter | number | <optional> | 1 | |
sides | number | <optional> | 8 | |
density | number | <optional> | ||
friction | number | <optional> | ||
restitution | number | <optional> | ||
isSensor | boolean | <optional> |
- Source
addShape(shape, densityopt, frictionopt, restitutionopt, isSensoropt)
Add a shape fixture to the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
shape | Object | |||
density | number | <optional> | 1 | |
friction | number | <optional> | 0.2 | |
restitution | number | <optional> | 0 | |
isSensor | boolean | <optional> | false |
- Source
applyAcceleration(acceleration, posopt)
Apply acceleration to this object
Name | Type | Attributes | Description |
---|---|---|---|
acceleration | Vector2 | ||
pos | Vector2 | <optional> |
- Source
applyAngularAcceleration(acceleration)
Apply angular acceleration to this object
Name | Type | Description |
---|---|---|
acceleration | number |
- Source
applyForce(force, posopt)
Apply force to this object
Name | Type | Attributes | Description |
---|---|---|---|
force | Vector2 | ||
pos | Vector2 | <optional> |
- Source
applyTorque(torque)
Apply torque to this object
Name | Type | Description |
---|---|---|
torque | number |
- Source
beginContact(otherObject)
Called when a contact begins
Name | Type | Description |
---|---|---|
otherObject | Box2dObject |
- Source
destroy()
Destroy this object and its physics body
- Source
drawFixtures(coloropt, lineColoropt, lineWidthopt, contextopt)
Draws all this object's fixtures
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
color | Color | <optional> | ||
lineColor | Color | <optional> | ||
lineWidth | number | <optional> | 0.1 | |
context | CanvasRenderingContext2D | <optional> |
- Source
endContact(otherObject)
Called when a contact ends
Name | Type | Description |
---|---|---|
otherObject | Box2dObject |
- Source
getAngularVelocity() → {Vector2}
Gets the angular velocity
- Source
- Type:
- Vector2
getBodyType() → {number}
Gets the physics body type
- Source
- Type:
- number
getCenterOfMass() → {Vector2}
Gets the center of mass
- Source
- Type:
- Vector2
getFixtureList() → {Array.<Object>}
Get list of fixtures for this object
- Source
- Type:
- Array.<Object>
getInertia() → {number}
Gets the rotational inertia
- Source
- Type:
- number
getIsAwake() → {boolean}
Check if this object is awake
- Source
- Type:
- boolean
getJointList() → {Array.<Object>}
Get list of joints for this object
- Source
- Type:
- Array.<Object>
getLinearVelocity() → {Vector2}
Gets the linear velocity
- Source
- Type:
- Vector2
getMass() → {number}
Gets the mass
- Source
- Type:
- number
hasFixtures() → {boolean}
Check if this object has any fixtures
- Source
- Type:
- boolean
hasJoints() → {boolean}
Check if this object has any joints
- Source
- Type:
- boolean
render()
Render the object, uses box2d drawing if no tile info exists
- Source
renderDebugInfo()
Render debug info
- Source
resetMassData()
Reset the mass, center of mass, and moment
- Source
setAngle(angle)
Sets the angle
Name | Type | Description |
---|---|---|
angle | number |
- Source
setAngularDamping(damping)
Sets the angular damping
Name | Type | Description |
---|---|---|
damping | number |
- Source
setAngularVelocity(angularVelocity)
Sets the angular velocity
Name | Type | Description |
---|---|---|
angularVelocity | number |
- Source
setAwake(isAwakeopt)
Set the sleep state of the body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isAwake | boolean | <optional> | true |
- Source
setBodyType(type)
Set the physics body type
Name | Type | Description |
---|---|---|
type | number |
- Source
setBullet(isBulletopt)
Should this body be treated like a bullet for continuous collision detection?
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isBullet | boolean | <optional> | true |
- Source
setCenterOfMass(center)
Set the center of mass of the body
Name | Type | Description |
---|---|---|
center | Vector2 |
- Source
setFilterData(categoryBitsopt, ignoreCategoryBitsopt, groupIndexopt)
Set the collision filter data for this body
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
categoryBits | number | <optional> | 0 | |
ignoreCategoryBits | number | <optional> | 0 | |
groupIndex | number | <optional> | 0 |
- Source
setFixedRotation(isFixedopt)
Set whether the body can rotate
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isFixed | boolean | <optional> | true |
- Source
setGravityScale(scaleopt)
Sets the gravity scale
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
scale | number | <optional> | 1 |
- Source
setLinearDamping(damping)
Sets the linear damping
Name | Type | Description |
---|---|---|
damping | number |
- Source
setLinearVelocity(velocity)
Sets the linear velocity
Name | Type | Description |
---|---|---|
velocity | Vector2 |
- Source
setMass(mass)
Set the mass of the body
Name | Type | Description |
---|---|---|
mass | number |
- Source
setMassData(localCenteropt, massopt, momentOfInertiaopt)
Set the mass data of the body
Name | Type | Attributes | Description |
---|---|---|---|
localCenter | Vector2 | <optional> | |
mass | number | <optional> | |
momentOfInertia | number | <optional> |
- Source
setMomentOfInertia(momentOfInertia)
Set the moment of inertia of the body
Name | Type | Description |
---|---|---|
momentOfInertia | number |
- Source
setPosition(pos)
Sets the position
Name | Type | Description |
---|---|---|
pos | Vector2 |
- Source
setSensor(isSensoropt)
Set if this body is a sensor
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isSensor | boolean | <optional> | true |
- Source
setSleepingAllowed(isAllowedopt)
Set whether the body is allowed to sleep
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
isAllowed | boolean | <optional> | true |
- Source
setTransform(pos, angle)
Sets the position and angle
Name | Type | Description |
---|---|---|
pos | Vector2 | |
angle | number |
- Source
update()
Copy box2d update sim data
- Source