b2Body Class
A rigid body. These are created via b2World.createBody().
Item Index
Methods
- advance
- applyForce
- applyForce
- applyImpulse
- applyImpulse
- applyTorque
- createFixture
- createFixtureShape
- destroyFixture
- getAngle
- getAngularDamping
- getAngularVelocity
- getContactList
- getControllerCount
- getControllerList
- getDefinition
- getFixtureList
- getGravityScale
- getInertia
- getJointList
- getLinearDamping
- getLinearVelocity
- getLinearVelocityFromLocalPoint
- getLinearVelocityFromWorldPoint
- getLocalCenter
- getLocalPoint
- getLocalVector
- getMass
- getMassData
- getNext
- getPosition
- getRotation
- getTransform
- getUserData
- getWorld
- getWorldCenter
- getWorldPoint
- getWorldVector
- isActive
- isAwake
- isBullet
- isFixedRotation
- isSleepingAllowed
- merge
- resetMassData
- setActive
- setAngle
- setAngularDamping
- setAngularDamping
- setAngularVelocity
- setAwake
- setBullet
- setFixedRotation
- setLinearDamping
- setLinearVelocity
- setMassData
- setPosition
- setPositionAndAngle
- setRotation
- setSleepingAllowed
- setTransform
- setType
- setUserData
- shouldCollide
- split
- synchronizeFixtures
- synchronizeTransform
Properties
- _sweep
- b2_bulletBody static
- b2_dynamicBody static
- b2_kinematicBody static
- b2_staticBody static
- b2_staticBody static
- e_activeFlag static
- e_allowSleepFlag static
- e_awakeFlag static
- e_bulletFlag static
- e_fixedRotationFlag static
- e_islandFlag static
- m_angularDamping
- m_angularVelocity
- m_contactList
- m_controllerCount
- m_controllerList
- m_fixtureCount
- m_fixtureList
- m_flags
- m_force
- m_I
- m_inertiaScale
- m_invI
- m_invMass
- m_jointList
- m_linearDamping
- m_linearVelocity
- m_mass
- m_next
- m_prev
- m_sleepTime
- m_sweep
- m_torque
- m_type
- m_userData
- m_world
- m_xf
- m_xf0
Methods
advance
-
alpha
Advance to the new safe time. This doesn't sync the broad-phase.
Parameters:
-
alpha
NumberThe original start time.
Returns:
applyForce
-
force
-
[wake=true]
Apply a force to the center of mass. This wakes up the body by default.
Parameters:
-
force
B2Vec2The world force vector, usually in Newtons (N).
-
[wake=true]
Boolean= optionalAlso wake up the body.
Returns:
applyForce
-
force
-
point
-
[wake=true]
Apply a force at a world point. If the force is not applied at the center of mass, it will generate a torque and affect the angular velocity. This wakes up the body by default.
Parameters:
-
force
B2Vec2The world force vector, usually in Newtons (N).
-
point
B2Vec2The world position of the point of application.
-
[wake=true]
Boolean= optionalAlso wake up the body.
Returns:
applyImpulse
-
impulse
-
[wake=true]
Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body by default.
Parameters:
-
impulse
FloatThe world impulse vector, usually in N-seconds or kg-m/s.
-
[wake=true]
Boolean= optionalAlso wake up the body.
Returns:
applyImpulse
-
impulse
-
point
-
[wake=true]
Apply an impulse at a point. This immediately modifies the velocity. It also modifies the angular velocity if the point of application is not at the center of mass. This wakes up the body by default.
Parameters:
-
impulse
FloatThe world impulse vector, usually in N-seconds or kg-m/s.
-
point
FloatThe world position of the point of application.
-
[wake=true]
Boolean= optionalAlso wake up the body.
Returns:
applyTorque
-
[torque=0.0]
-
[wake=true]
Apply a torque. This affects the angular velocity without affecting the linear velocity of the center of mass. This wakes up the body by default.
Parameters:
-
[torque=0.0]
Float optionalAbout the z-axis (out of the screen), usually in N-m.
-
[wake=true]
Boolean= optionalAlso wake up the body.
Returns:
createFixture
-
def
Creates a fixture and attach it to 'this' body instance. Use this function if you need to set some fixture parameters, like friction. Otherwise you can create the fixture directly from a shape's Set(As)...() methods. If the density is non-zero, this function automatically updates the mass of the body. Contacts are not created until the next time step.
Warning: This function is locked during callbacks. NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.
Parameters:
-
def
B2FixtureDefThe fixture definition.
Returns:
createFixtureShape
-
shape
-
density
Creates a fixture from a shape and attach it to this body. This is a convenience function. Use b2FixtureDef if you need to set parameters like friction, restitution, user data, or filtering. If the density is non-zero, this function automatically updates the mass of the body.
Warning: This function is locked during callbacks. NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.
Parameters:
-
shape
B2ShapeThe shape to be cloned.
-
density
FloatThe shape density (set to zero for static bodies).
Returns:
destroyFixture
-
fixture
Destroy a fixture. This removes the fixture from the broad-phase and destroys all contacts associated with this fixture. This will automatically adjust the mass of the body if the body is dynamic and the fixture has positive density. All fixtures attached to a body are implicitly destroyed when the body is destroyed.
Warning: This function is locked during callbacks. NOTE: However using the addPhysicsJS framework event listeners you can do what every you want whenever you want and addPhysicsJS manages the locked world problems for you.
Parameters:
-
fixture
B2FixtureThe fixture to be removed.
Returns:
getAngle
()
Float
public
Get the angle in radians.
Returns:
The current world rotation angle in radians.
getAngularDamping
()
Float
public
Returns:
getAngularVelocity
()
Float
public
Get the angular velocity.
Returns:
The angular velocity in radians/second.
getContactList
()
B2ContactEdge
public
Get the list of all contacts attached to this body.
Warning: This list changes during the time step and you may miss some collisions if you don't use b2ContactListener.
Returns:
getDefinition
-
[bodyDef=b2BodyDef]
Parameters:
-
[bodyDef=b2BodyDef]
B2BodyDef optionalreusable object
Returns:
out
getFixtureList
()
B2Fixture
public
Get the list of all fixtures attached to this body.
Returns:
getGravityScale
()
Float
public
Get the gravity scale of the body.
Returns:
getInertia
()
Float
public
Get the rotational inertia of the body about the local origin.
Returns:
The rotational inertia, usually in kg-m^2.
getJointList
()
B2JointEdge
public
Get the list of all joints attached to this body.
Returns:
getLinearDamping
()
Float
public
Get the linear damping of the body.
Returns:
getLinearVelocity
-
[out=b2Vec2]
Get the linear velocity of the center of mass.
Parameters:
-
[out=b2Vec2]
Object | B2Vec2= optionalreusable object
Returns:
out
getLinearVelocityFromLocalPoint
-
localPoint
-
[out=b2Vec2]
Get the world velocity of a local point.
Parameters:
-
localPoint
B2Vec2A point in local coordinates
-
[out=b2Vec2]
B2Vec2 | Object= optionalReusable vector object.
Returns:
The world velocity of a point.
getLinearVelocityFromWorldPoint
-
worldPoint
-
[out=b2Vec2]
Get the world linear velocity of a world point attached to this body.
Parameters:
-
worldPoint
B2Vec2A point in world coordinates.
-
[out=b2Vec2]
B2Vec2 | Object= optionalReusable vector object.
Returns:
The world velocity of a point.
getLocalCenter
-
[out=b2Vec2]
Get the local position of the center of mass.
Parameters:
-
[out=b2Vec2]
Object | B2Vec2= optionalreusable object
Returns:
out
getLocalPoint
-
worldPoint
-
[out=b2Vec2]
Gets a local point relative to the body's origin given a world point.
Parameters:
-
worldPoint
B2Vec2A point in world coordinates.
-
[out=b2Vec2]
Object | B2Vec2= optionalReusable object.
Returns:
out The corresponding local point relative to the body's origin.
getLocalVector
-
worldVector
-
[out=b2Vec2]
Gets a local vector given a world vector.
Parameters:
-
worldVector
B2Vec2A vector in world coordinates.
-
[out=b2Vec2]
Object | B2Vec2= optionalReusable object.
Returns:
out The corresponding local vector.
getMass
()
Float
public
Get the total mass of the body.
Returns:
The mass, usually in kilograms (kg).
getMassData
-
massData
Get the mass data of the body.
Parameters:
-
massData
B2MassData
Returns:
massData Containing the mass, inertia and center of the body.
getNext
()
B2Body
public
Get the next body in the world's body list.
Returns:
getPosition
-
[out=b2Vec2]
Get the world body origin position.
Parameters:
-
[out=b2Vec2]
Object | B2Vec2= optionalreusable object.
Returns:
out The world position of the body's origin.
getRotation
-
[out=b2Transform]
Get the world body origin rotation.
Parameters:
-
[out=b2Transform]
Object | B2Transform= optionalreusable object.
Returns:
out The current world rotation angle on a b2Transform.
getTransform
-
[out=b2Transform]
Get the body transform for the body's origin.
Parameters:
-
[out=b2Transform]
Object | B2Transform= optionalreusable object.
Returns:
The world transform of the body's origin.
getUserData
()
public
Get the user data reference that was provided by the body definition.
Returns:
getWorld
()
B2World
public
Get the parent world of this body.
Returns:
getWorldCenter
-
[out=b2Vec2]
Get the world position of the center of mass.
Parameters:
-
[out=b2Vec2]
Object | B2Vec2= optionalreusable object
Returns:
out
getWorldPoint
-
localPoint
-
[out=b2Vec2]
Get the world coordinates of a point given the local coordinates.
Parameters:
-
localPoint
B2Vec2A point on the body measured relative the the body's origin.
-
[out=b2Vec2]
Object | B2Vec2= optionalReusable object.
Returns:
out A point expressed in world coordinates.
getWorldVector
-
localVector
-
[out=b2Vec2]
Get the world coordinates of a vector given the local coordinates.
Parameters:
-
localVector
B2Vec2A vector fixed in the body.
-
[out=b2Vec2]
Object | B2Vec2= optionalReusable object.
Returns:
out Expressed in world coordinates.
isBullet
()
Boolean
public
Is this body treated like a bullet for continuous collision detection?
Returns:
merge
-
other
Merges two bodies into one.
Parameters:
-
other
B2Body
Returns:
resetMassData
()
Void
public
This resets the mass properties to the sum of the mass properties of the fixtures. This normally does not need to be called unless you called SetMassData to override the mass and you later want to reset the mass.
Returns:
setActive
-
active
Set the active state of the body.
An inactive body is not simulated and cannot be collided with or woken up. If you pass a flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from the broad-phase and all contacts will be destroyed.
Fixtures and joints are otherwise unaffected. You may continue to create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not participate in collisions, ray-casts, or queries.
Joints connected to an inactive body are implicitly inactive. An inactive body is still owned by a b2World object and remains in the body list.
Parameters:
-
active
Boolean
Returns:
setAngle
-
[angle=0.0]
Parameters:
-
[angle=0.0]
Float= optionalIn radians.
Returns:
setAngularDamping
-
scale
Get the gravity scale of the body.
Parameters:
-
scale
Float
Returns:
setAngularDamping
-
[angularDamping=0.0]
Get the angular damping of the body.
Parameters:
-
[angularDamping=0.0]
Float optional
Returns:
setAngularVelocity
-
omega
Set the angular velocity.
Parameters:
-
omega
FloatThe new angular velocity in radians/second.
Returns:
setAwake
-
flag
Set the sleep state of the body. A sleeping body has very low CPU cost.
Parameters:
-
flag
BooleanSet to TRUE to wake the body, FALSE to put it to sleep.
Returns:
setBullet
-
flag
Should this body be treated like a bullet for continuous collision detection?
Parameters:
-
flag
Boolean
Returns:
setFixedRotation
()
Boolean
public
Set this body to have fixed rotation. This causes the mass to be reset.
Returns:
true if the body is awake.
setLinearDamping
-
[damping=0.0]
Set the linear damping of the body.
Parameters:
-
[damping=0.0]
Float optional
Returns:
setLinearVelocity
-
velocity
Set the linear velocity of the center of mass.
Parameters:
-
velocity
B2Vec2The new linear velocity of the center of mass.
Returns:
setMassData
-
massData
Set the mass properties to override the mass properties of the fixtures. Note that this changes the center of mass position. Note that creating or destroying fixtures can also alter the mass. This function has no effect if the body isn't dynamic.
Parameters:
-
massData
B2MassDataThe mass properties.
Returns:
setPosition
-
position
Parameters:
-
position
B2Vec2
Returns:
setPositionAndAngle
-
position
-
angle
Set the position of the body's origin and rotation. Manipulating a body's transform may cause non-physical behavior.
Note: contacts are updated on the next call to b2World.step().
Parameters:
-
position
B2Vec2The world position of the body's local origin.
-
angle
FloatThe world rotation in radians.
Returns:
setRotation
-
[rotation=0.0]
Set the world body origin rotation.
Parameters:
-
[rotation=0.0]
Float= optionalIn radians.
Returns:
setSleepingAllowed
()
Boolean
public
You can disable sleeping on this body. If you disable sleeping, the body will be woken.
Returns:
setTransform
-
transform
Set the body transform for the body.
Parameters:
-
transform
B2Transform
Returns:
setType
-
type
Set the type of this body. This may alter the mass and velocity.
Parameters:
-
type
Int
Returns:
setUserData
-
data
Set the user data. Use this to store your application specific data.
Parameters:
-
data
Returns:
shouldCollide
-
other
This is used to prevent connected bodies from colliding. It may lie, depending on the collideConnected flag.
Parameters:
-
other
B2Body
Returns:
split
-
callback
Splits a body into two bodies.
Parameters:
-
callback
B2QueryCallback
Returns:
synchronizeFixtures
()
Void
public
Returns:
synchronizeTransform
()
Void
public
Returns:
Properties
_sweep
B2Sweep
private
Getter memory management.
b2_bulletBody
Binary
default 2
public
static
b2_dynamicBody
Binary
default 2
public
static
Dynamic: positive mass, non-zero velocity determined by forces, moved by solver.
b2_kinematicBody
Binary
default 1
public
static
Kinematic: zero mass, non-zero velocity set by user, moved by solver.
b2_staticBody
Binary
default 0
public
static
Static: zero mass, zero velocity, may be manually moved.
b2_staticBody
Binary
default -1
public
static
b2BodyDef base class default: unknown.
e_activeFlag
Binary
default 0x0020
public
static
e_allowSleepFlag
Binary
default 0x0004
public
static
e_awakeFlag
Binary
default 0x0002
public
static
e_bulletFlag
Binary
default 0x0008
public
static
e_fixedRotationFlag
Binary
default 0x0010
public
static
e_islandFlag
Binary
default 0x0001
public
static
m_angularDamping
Int
public
Default: b2bodyDef.angularDamping
m_angularVelocity
Float
public
The angular velocity of the body.
Default: b2bodyDef.angularVelocity
m_contactList
B2ContactEdge | Null
public
Default: null
m_controllerCount
Int
public
Default: 0
m_controllerList
B2ControllerEdge | Null
public
Default: null
m_fixtureCount
Int
public
Default: 0
m_fixtureList
B2Fixture | Null
public
Default: null
m_flags
Binary
public
Default: 0
m_force
B2Vec2
public
m_I
Float
public
Rotational inertia about the center of mass.
Default: 0.0
m_inertiaScale
Float
public
For inertia (perceived gravity) scaling.
Default: b2bodyDef.inertiaScale
m_invI
Float
public
Inverse rotational inertia about the center of mass.
Default: 0.0
m_invMass
Float
public
Body's inverse mass.
Default: 0.0
m_jointList
B2JointEdge | Null
public
Default: null
m_linearDamping
Int
public
Linear damping is use to reduce the linear velocity. The damping parameter can be larger than 1.0f but the damping effect becomes sensitive to the time step when the damping parameter is large.
Default: b2bodyDef.linearDamping
m_linearVelocity
B2Vec2
public
m_mass
Float
public
Body's mass.
Default: 0.0
m_next
B2Body | Null
public
The next body in the world's 'bodies linked-list'. Maybe null if 'this' body instance is the 'head' of the linked-list.
Default: null
m_prev
B2Body | Null
public
The previous body in the world's 'bodies linked-list'.
Default: null
m_sleepTime
Float
public
Default: 0
m_sweep
B2Sweep
public
The swept motion for continuous collision detection.
m_torque
Float
public
Default: 0
m_type
Int
public
The body type: Static, Dynamic or Kinematic.
NOTE: The addPhysicsJS framework adds a fourth type: Tweened. TODO crosslink addPhysicsJS API Tweened is a Kinematic body moved by a FlashCC timeline tween. addPhysicsJS translates the timeline tween motion into linear and angular velocities applied appropriately to its corresponding kinematic b2Body in the b2World simulation.
Default: b2bodyDef.type
m_userData
public
Application specific data.
NOTE: Using the addPhysicsJS framework m_userData is managed for you extending either a createjs.container or createjs.movieClip class.
Default: b2bodyDef.userData
m_world
B2World
public
m_xf
B2Transform
public
The body origin transform.
m_xf0
B2Transform
public
The previous transform for particle simulation. Only used by the Particle and ParticleSystem Module's.