API Documentation for:
Show:

b2Body Class

Defined in: b2Body:19
Module: Dynamics

A rigid body. These are created via b2World.createBody().

Item Index

Methods

advance

(
  • alpha
)
Void public

Defined in advance:1910

Advance to the new safe time. This doesn't sync the broad-phase.

Parameters:

  • alpha Number

    The original start time.

Returns:

Void:

applyForce

(
  • force
  • [wake=true]
)
Void public

Defined in applyForce:1045

Apply a force to the center of mass. This wakes up the body by default.

Parameters:

  • force B2Vec2

    The world force vector, usually in Newtons (N).

  • [wake=true] Boolean= optional

    Also wake up the body.

Returns:

Void:

applyForce

(
  • force
  • point
  • [wake=true]
)
Void public

Defined in applyForce:1017

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 B2Vec2

    The world force vector, usually in Newtons (N).

  • point B2Vec2

    The world position of the point of application.

  • [wake=true] Boolean= optional

    Also wake up the body.

Returns:

Void:

applyImpulse

(
  • impulse
  • [wake=true]
)
Void public

Defined in applyImpulse:1123

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 Float

    The world impulse vector, usually in N-seconds or kg-m/s.

  • [wake=true] Boolean= optional

    Also wake up the body.

Returns:

Void:

applyImpulse

(
  • impulse
  • point
  • [wake=true]
)
Void public

Defined in applyImpulse:1094

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 Float

    The world impulse vector, usually in N-seconds or kg-m/s.

  • point Float

    The world position of the point of application.

  • [wake=true] Boolean= optional

    Also wake up the body.

Returns:

Void:

applyTorque

(
  • [torque=0.0]
  • [wake=true]
)
Void public

Defined in applyTorque:1069

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 optional

    About the z-axis (out of the screen), usually in N-m.

  • [wake=true] Boolean= optional

    Also wake up the body.

Returns:

Void:

createFixture

(
  • def
)
B2Fixture public

Defined in createFixture:598

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 B2FixtureDef

    The fixture definition.

Returns:

B2Fixture:

createFixtureShape

(
  • shape
  • density
)
B2Fixture public

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 B2Shape

    The shape to be cloned.

  • density Float

    The shape density (set to zero for static bodies).

Returns:

B2Fixture:

destroyFixture

(
  • fixture
)
Void public

Defined in destroyFixture:681

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 B2Fixture

    The fixture to be removed.

Returns:

Void:

getAngle

() Float public

Defined in getAngle:859

Get the angle in radians.

Returns:

Float:

The current world rotation angle in radians.

getAngularDamping

() Float public

Returns:

Float:

getAngularVelocity

() Float public

Get the angular velocity.

Returns:

Float:

The angular velocity in radians/second.

getContactList

() B2ContactEdge public

Defined in getContactList:1797

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:

B2ContactEdge:

getControllerCount

() Int public

See b2Controller list.

Returns:

Int:

getControllerList

() B2ControllerEdge public

See b2Controller list.

Returns:

B2ControllerEdge:

getDefinition

(
  • [bodyDef=b2BodyDef]
)
B2BodyDef public

Defined in getDefinition:992

Parameters:

  • [bodyDef=b2BodyDef] B2BodyDef optional

    reusable object

Returns:

B2BodyDef:

out

getFixtureList

() B2Fixture public

Defined in getFixtureList:1775

Get the list of all fixtures attached to this body.

Returns:

B2Fixture:

getGravityScale

() Float public

Get the gravity scale of the body.

Returns:

Float:

getInertia

() Float public

Defined in getInertia:1160

Get the rotational inertia of the body about the local origin.

Returns:

Float:

The rotational inertia, usually in kg-m^2.

getJointList

() B2JointEdge public

Defined in getJointList:1786

Get the list of all joints attached to this body.

Returns:

B2JointEdge:

getLinearDamping

() Float public

Get the linear damping of the body.

Returns:

Float:

getLinearVelocity

(
  • [out=b2Vec2]
)
Object | B2Vec2 public

Get the linear velocity of the center of mass.

Parameters:

  • [out=b2Vec2] Object | B2Vec2= optional

    reusable object

Returns:

Object | B2Vec2:

out

getLinearVelocityFromLocalPoint

(
  • localPoint
  • [out=b2Vec2]
)
B2Vec2 | Object public

Get the world velocity of a local point.

Parameters:

  • localPoint B2Vec2

    A point in local coordinates

  • [out=b2Vec2] B2Vec2 | Object= optional

    Reusable vector object.

Returns:

B2Vec2 | Object:

The world velocity of a point.

getLinearVelocityFromWorldPoint

(
  • worldPoint
  • [out=b2Vec2]
)
B2Vec2 | Object public

Get the world linear velocity of a world point attached to this body.

Parameters:

  • worldPoint B2Vec2

    A point in world coordinates.

  • [out=b2Vec2] B2Vec2 | Object= optional

    Reusable vector object.

Returns:

B2Vec2 | Object:

The world velocity of a point.

getLocalCenter

(
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getLocalCenter:920

Get the local position of the center of mass.

Parameters:

  • [out=b2Vec2] Object | B2Vec2= optional

    reusable object

Returns:

Object | B2Vec2:

out

getLocalPoint

(
  • worldPoint
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getLocalPoint:1347

Gets a local point relative to the body's origin given a world point.

Parameters:

  • worldPoint B2Vec2

    A point in world coordinates.

  • [out=b2Vec2] Object | B2Vec2= optional

    Reusable object.

Returns:

Object | B2Vec2:

out The corresponding local point relative to the body's origin.

getLocalVector

(
  • worldVector
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getLocalVector:1360

Gets a local vector given a world vector.

Parameters:

  • worldVector B2Vec2

    A vector in world coordinates.

  • [out=b2Vec2] Object | B2Vec2= optional

    Reusable object.

Returns:

Object | B2Vec2:

out The corresponding local vector.

getMass

() Float public

Defined in getMass:1149

Get the total mass of the body.

Returns:

Float:

The mass, usually in kilograms (kg).

getMassData

(
  • massData
)
B2MassData public

Defined in getMassData:1171

Get the mass data of the body.

Parameters:

  • massData B2MassData

Returns:

B2MassData:

massData Containing the mass, inertia and center of the body.

getNext

() B2Body public

Defined in getNext:1812

Get the next body in the world's body list.

Returns:

B2Body:

getPosition

(
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getPosition:836

Get the world body origin position.

Parameters:

  • [out=b2Vec2] Object | B2Vec2= optional

    reusable object.

Returns:

Object | B2Vec2:

out The world position of the body's origin.

getRotation

(
  • [out=b2Transform]
)
Object | B2Transform public

Defined in getRotation:881

Get the world body origin rotation.

Parameters:

  • [out=b2Transform] Object | B2Transform= optional

    reusable object.

Returns:

Object | B2Transform:

out The current world rotation angle on a b2Transform.

getTransform

(
  • [out=b2Transform]
)
Object | B2Transform public

Defined in getTransform:823

Get the body transform for the body's origin.

Parameters:

  • [out=b2Transform] Object | B2Transform= optional

    reusable object.

Returns:

Object | B2Transform:

The world transform of the body's origin.

getUserData

() public

Defined in getUserData:1823

Get the user data reference that was provided by the body definition.

Returns:

:

getWorld

() B2World public

Defined in getWorld:1846

Get the parent world of this body.

Returns:

B2World:

getWorldCenter

(
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getWorldCenter:907

Get the world position of the center of mass.

Parameters:

  • [out=b2Vec2] Object | B2Vec2= optional

    reusable object

Returns:

Object | B2Vec2:

out

getWorldPoint

(
  • localPoint
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getWorldPoint:1321

Get the world coordinates of a point given the local coordinates.

Parameters:

  • localPoint B2Vec2

    A point on the body measured relative the the body's origin.

  • [out=b2Vec2] Object | B2Vec2= optional

    Reusable object.

Returns:

Object | B2Vec2:

out A point expressed in world coordinates.

getWorldVector

(
  • localVector
  • [out=b2Vec2]
)
Object | B2Vec2 public

Defined in getWorldVector:1334

Get the world coordinates of a vector given the local coordinates.

Parameters:

  • localVector B2Vec2

    A vector fixed in the body.

  • [out=b2Vec2] Object | B2Vec2= optional

    Reusable object.

Returns:

Object | B2Vec2:

out Expressed in world coordinates.

isActive

() Boolean public

Defined in isActive:1749

Get the active state of the body.

Returns:

isAwake

() Boolean public

Defined in isAwake:1636

Get the sleeping state of this body.

Returns:

isBullet

() Boolean public

Defined in isBullet:1557

Is this body treated like a bullet for continuous collision detection?

Returns:

isFixedRotation

() Boolean public

Does this body have fixed rotation?

Returns:

isSleepingAllowed

() Boolean public

Is this body allowed to sleep

Returns:

merge

(
  • other
)
Void public

Defined in merge:2014

Merges two bodies into one.

Parameters:

Returns:

Void:

resetMassData

() Void public

Defined in resetMassData:1241

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:

Void:

setActive

(
  • active
)
Void public

Defined in setActive:1688

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:

Returns:

Void:

setAngle

(
  • [angle=0.0]
)
Void public

Defined in setAngle:870

Parameters:

  • [angle=0.0] Float= optional

    In radians.

Returns:

Void:

setAngularDamping

(
  • scale
)
Void public

Get the gravity scale of the body.

Parameters:

  • scale Float

Returns:

Void:

setAngularDamping

(
  • [angularDamping=0.0]
)
Void public

Get the angular damping of the body.

Parameters:

  • [angularDamping=0.0] Float optional

Returns:

Void:

setAngularVelocity

(
  • omega
)
Void public

Set the angular velocity.

Parameters:

  • omega Float

    The new angular velocity in radians/second.

Returns:

Void:

setAwake

(
  • flag
)
Void public

Defined in setAwake:1597

Set the sleep state of the body. A sleeping body has very low CPU cost.

Parameters:

  • flag Boolean

    Set to TRUE to wake the body, FALSE to put it to sleep.

Returns:

Void:

setBullet

(
  • flag
)
Void public

Defined in setBullet:1538

Should this body be treated like a bullet for continuous collision detection?

Parameters:

Returns:

Void:

setFixedRotation

() Boolean public

Set this body to have fixed rotation. This causes the mass to be reset.

Returns:

Boolean:

true if the body is awake.

setLinearDamping

(
  • [damping=0.0]
)
Void public

Set the linear damping of the body.

Parameters:

  • [damping=0.0] Float optional

Returns:

Void:

setLinearVelocity

(
  • velocity
)
Void public

Set the linear velocity of the center of mass.

Parameters:

  • velocity B2Vec2

    The new linear velocity of the center of mass.

Returns:

Void:

setMassData

(
  • massData
)
Void public

Defined in setMassData:1186

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 B2MassData

    The mass properties.

Returns:

Void:

setPosition

(
  • position
)
Void public

Defined in setPosition:849

Parameters:

  • position B2Vec2

Returns:

Void:

setPositionAndAngle

(
  • position
  • angle
)
Void public

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 B2Vec2

    The world position of the body's local origin.

  • angle Float

    The world rotation in radians.

Returns:

Void:

setRotation

(
  • [rotation=0.0]
)
Void public

Defined in setRotation:894

Set the world body origin rotation.

Parameters:

  • [rotation=0.0] Float= optional

    In radians.

Returns:

Void:

setSleepingAllowed

() Boolean public

You can disable sleeping on this body. If you disable sleeping, the body will be woken.

Returns:

setTransform

(
  • transform
)
Void public

Defined in setTransform:810

Set the body transform for the body.

Parameters:

  • transform B2Transform

Returns:

Void:

setType

(
  • type
)
Void public

Defined in setType:1473

Set the type of this body. This may alter the mass and velocity.

Parameters:

  • type Int

Returns:

Void:

setUserData

(
  • data
)
Void public

Defined in setUserData:1834

Set the user data. Use this to store your application specific data.

Parameters:

  • data

Returns:

Void:

shouldCollide

(
  • other
)
Boolean public

Defined in shouldCollide:1885

This is used to prevent connected bodies from colliding. It may lie, depending on the collideConnected flag.

Parameters:

Returns:

split

(
  • callback
)
B2Body public

Defined in split:1956

Splits a body into two bodies.

Parameters:

  • callback B2QueryCallback

Returns:

B2Body:

synchronizeFixtures

() Void public

Returns:

Void:

synchronizeTransform

() Void public

Returns:

Void:

Properties

_sweep

B2Sweep private

Defined in _sweep:80

Getter memory management.

b2_bulletBody

Binary default 2 public static

Defined in b2_bulletBody:483

b2_dynamicBody

Binary default 2 public static

Defined in b2_dynamicBody:472

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

Defined in b2_staticBody:450

Static: zero mass, zero velocity, may be manually moved.

b2_staticBody

Binary default -1 public static

Defined in b2_staticBody:439

b2BodyDef base class default: unknown.

e_activeFlag

Binary default 0x0020 public static

Defined in e_activeFlag:539

e_allowSleepFlag

Binary default 0x0004 public static

e_awakeFlag

Binary default 0x0002 public static

Defined in e_awakeFlag:503

e_bulletFlag

Binary default 0x0008 public static

Defined in e_bulletFlag:521

e_fixedRotationFlag

Binary default 0x0010 public static

e_islandFlag

Binary default 0x0001 public static

Defined in e_islandFlag:494

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

Defined in m_contactList:390

Default: null

m_controllerCount

Int public

Default: 0

m_controllerList

B2ControllerEdge | Null public

Default: null

m_fixtureCount

Int public

Defined in m_fixtureCount:350

Default: 0

m_fixtureList

B2Fixture | Null public

Defined in m_fixtureList:342

Default: null

m_flags

Binary public

Defined in m_flags:152

Default: 0

m_force

B2Vec2 public

Defined in m_force:96

m_I

Float public

Defined in m_I:304

Rotational inertia about the center of mass.

Default: 0.0

m_inertiaScale

Float public

Defined in m_inertiaScale:228

For inertia (perceived gravity) scaling.

Default: b2bodyDef.inertiaScale

m_invI

Float public

Defined in m_invI:314

Inverse rotational inertia about the center of mass.

Default: 0.0

m_invMass

Float public

Defined in m_invMass:293

Body's inverse mass.

Default: 0.0

m_jointList

B2JointEdge | Null public

Defined in m_jointList:382

Default: null

m_linearDamping

Int public

Defined in m_linearDamping:207

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

Defined in m_linearVelocity:89

m_mass

Float public

Defined in m_mass:283

Body's mass.

Default: 0.0

m_next

B2Body | Null public

Defined in m_next:408

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

Defined in m_prev:398

The previous body in the world's 'bodies linked-list'.

Default: null

m_sleepTime

Float public

Defined in m_sleepTime:246

Default: 0

m_sweep

B2Sweep public

Defined in m_sweep:71

The swept motion for continuous collision detection.

m_torque

Float public

Defined in m_torque:238

Default: 0

m_type

Int public

Defined in m_type:255

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

Defined in m_userData:324

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

Defined in m_world:172

m_xf

B2Transform public

Defined in m_xf:48

The body origin transform.

m_xf0

B2Transform public

Defined in m_xf0:58

The previous transform for particle simulation. Only used by the Particle and ParticleSystem Module's.