Class R.components.physics.BaseBody
Extends
R.components.Transform2D.
The base component which initializes rigid bodies
for use in a R.physics.Simulation.
Defined in: basebody.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.components.physics.BaseBody(name, fixtureDef)
All physical body components should extend from this component type
to inherit such values as density and friction, and gain access to position and rotation.
|
Field Attributes | Field Name and Description |
---|---|
The default density of a body
|
|
The default friction of a body
|
|
The default restitution (bounciness) of a body
|
- Fields borrowed from class R.components.Base:
- TYPE_COLLIDER, TYPE_INPUT, TYPE_LOGIC, TYPE_RENDERING, TYPE_TRANSFORM
Method Attributes | Method Name and Description |
---|---|
applyForce(forceVector, position)
Apply a force at a world point.
|
|
applyImpulse(impulseVector, position)
Apply an impulse at a point.
|
|
applyTorque(torque)
Apply torque to the body.
|
|
destroy()
Destroy the object
|
|
execute(renderContext, time, dt)
Checks a couple of flags on the body and triggers events when they change.
|
|
Get the angular damping of the body.
|
|
getBody()
Get the Box2d body object which was added to the simulation.
|
|
Get the Box2d body definition object.
|
|
[ABSTRACT] Get a box which bounds the body.
|
|
Get the center of the body.
|
|
Get the class name of this object
|
|
Get the density of the body.
|
|
Get the Box2d fixture definition object.
|
|
Get the friction of the body.
|
|
Get the linear damping of the body.
|
|
Get the local origin of the body.
|
|
getMass()
Get the total mass of the body.
|
|
Get the position of the body during simulation.
|
|
Get the associated render component for this body.
|
|
Get the resitution (bounciness) value for the body.
|
|
Get the rotation of the body.
|
|
isActive()
Returns
true if the body is active. |
|
Returns
true if the body is sleeping. |
|
isStatic()
Returns
true if the body is static. |
|
release()
Releases the object back into the pool
|
|
setActive(active)
Sets the active state of a body.
|
|
setDamping(linear, angular)
Sets the linear and angular damping of a body.
|
|
setDensity(density)
Set the density of the body.
|
|
setFriction(friction)
Set the friction of the body.
|
|
setLocalOrigin(x, y)
Set the origin of the rigid body.
|
|
setMass(mass)
Set the total mass of the body in kilograms.
|
|
setPosition(point)
Set the initial position of the body.
|
|
setRenderComponent(renderComponent)
Set the associated render component for this body.
|
|
setRestitution(restitution)
Set the resitution (bounciness) of the body.
|
|
setRotation(angle)
Set the angle of rotation for the body, in degrees.
|
|
setStatic(state)
Set a body to be static or dynamic.
|
|
Start simulating the body.
|
|
Stop simulating the body.
|
|
Update the fixture on a simulated body.
|
|
wakeUp()
Wake up a body, adding it back into the collection of bodies being simulated.
|
- Methods borrowed from class R.components.Transform2D:
- getLastPosition, getLastRenderPosition, getRenderPosition, getRenderRotation, getRenderScale, getRenderScaleX, getRenderScaleY, getScale, getScaleX, getScaleY, setLastPosition, setScale
- Methods borrowed from class R.components.Base:
- getGameObject, getHostObject, getPriority, getType, getTypeString, setGameObject, setHostObject, setPriority
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent, update
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, getId, getName, getObjectDataModel, getProperties, isDestroyed, setName, setObjectDataModel, toString, toXML
Class Detail
R.components.physics.BaseBody(name, fixtureDef)
All physical body components should extend from this component type
to inherit such values as density and friction, and gain access to position and rotation.
- Parameters:
- name
- {String} Name of the component
- fixtureDef
- {Box2D.Dynamics.b2FixtureDef} The fixture definition.
Field Detail
DEFAULT_DENSITY
The default density of a body
DEFAULT_FRICTION
The default friction of a body
DEFAULT_RESTITUTION
The default restitution (bounciness) of a body
Method Detail
applyForce(forceVector, position)
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.
Forces are comprised of a force vector and
a position. The force vector is the direction in which the force is
moving, while the position is where on the body the force is acting.
Forces act upon a body from world coordinates.
- Parameters:
- forceVector
- {R.math.Vector2D} The force vector
- position
- {R.math.Point2D} The position where the force is acting upon the body
applyImpulse(impulseVector, position)
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. Impulses are comprised of an impulse vector and
a position. The impulse vector is the direction of the impulse, while the position
is where on the body the impulse will be applied.
Impulses act upon a body locally, adjusting its velocity.
- Parameters:
- impulseVector
- {R.math.Vector2D} The impulse vectory
- position
- {R.math.Point2D} the position where the impulse is originating from in the body
applyTorque(torque)
Apply torque to the body. This affects the angular velocity without affecting the
linear velocity of the center of mass.
- Parameters:
- torque
- {Number} The amount of torque to apply to the body
destroy()
Destroy the object
execute(renderContext, time, dt)
Checks a couple of flags on the body and triggers events when they change. Fires
the
active
event on the game object when this body changes its "active" state.
Fires the sleeping
event on the game object when this body changes its
"sleeping" state. Both events are passed the body which changed state, and a flag
indicating the current state.
- Parameters:
- renderContext
- {R.rendercontexts.AbstractRenderContext} The rendering context
- time
- {Number} The engine time in milliseconds
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
{Number}
getAngularDamping()
Get the angular damping of the body.
- Returns:
- {Number}
{b2Body}
getBody()
Get the Box2d body object which was added to the simulation.
- Returns:
- {b2Body}
{b2BodyDef}
getBodyDef()
Get the Box2d body definition object.
- Returns:
- {b2BodyDef}
{R.math.Rectangle2D}
getBoundingBox()
[ABSTRACT] Get a box which bounds the body.
- Returns:
- {R.math.Rectangle2D}
{R.math.Point2D}
getCenter()
Get the center of the body.
- Returns:
- {R.math.Point2D}
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} "R.components.physics.BaseBody"
{Number}
getDensity()
Get the density of the body.
- Returns:
- {Number}
{Box2D.Dynamics.b2FixtureDef}
getFixtureDef()
Get the Box2d fixture definition object.
- Returns:
- {Box2D.Dynamics.b2FixtureDef}
{Number}
getFriction()
Get the friction of the body.
- Returns:
- {Number}
{Number}
getLinearDamping()
Get the linear damping of the body.
- Returns:
- {Number}
{R.math.Point2D}
getLocalOrigin()
Get the local origin of the body.
- Returns:
- {R.math.Point2D}
{Number}
getMass()
Get the total mass of the body. If the body is not simulating, this
returns
Infinity
.
- Returns:
- {Number} The mass of the body, or
Infinity
{R.math.Point2D}
getPosition()
Get the position of the body during simulation. This value is updated
as the simulation is stepped.
- Returns:
- {R.math.Point2D}
{R.components.Render}
getRenderComponent()
Get the associated render component for this body.
- Returns:
- {R.components.Render} or
null
{Number}
getRestitution()
Get the resitution (bounciness) value for the body.
- Returns:
- {Number}
{Number}
getRotation()
Get the rotation of the body. This value is updated as the simulation is stepped.
- Returns:
- {Number}
{Boolean}
isActive()
Returns
true
if the body is active. An active body is updated during
the simulation and can be collided with.
- Returns:
- {Boolean}
{Boolean}
isSleeping()
Returns
true
if the body is sleeping. A body is sleeping if it
has settled to the point where no movement is being calculated. If you want
to perform an action upon a body, other than applying force, torque, or impulses,
you must call #wakeUp.
- Returns:
- {Boolean}
{Boolean}
isStatic()
Returns
true
if the body is static. A body is static if it
isn't updated part of the simulation during contacts.
- Returns:
- {Boolean}
release()
Releases the object back into the pool
setActive(active)
Sets the active state of a body. Setting the active flag to false will
remove the object from simulation. Setting it to true will add it back into the
simulation.
- Parameters:
- active
- {Boolean} The activity flag
setDamping(linear, angular)
Sets the linear and angular damping of a body. Damping is used to reduce the
world velocity of bodies. Damping differs from friction in that friction
only occurs when two surfaces are in contact. Damping is not a replacement
for friction. A value between 0 and
Infinity
can be used, but
normally the value is between 0 and 1.0.
- Parameters:
- linear
- {Number} The amount of linear damping
- angular
- {Number} The amount of angular damping
setDensity(density)
Set the density of the body.
- Parameters:
- density
- {Number} The density of the body
setFriction(friction)
Set the friction of the body. Lower values slide easily across other bodies.
Higher values will cause a body to stop moving as it slides across other bodies.
However, even a body which has high friction will keep sliding across a body
with no friction.
- Parameters:
- friction
- {Number} The friction of the body
setLocalOrigin(x, y)
Set the origin of the rigid body. By default, the origin is the top left corner of
the bounding box for the body. Most times the origin should be set to the center
of the body.
- Parameters:
- x
- {Number|R.math.Point2D} The X coordinate or a Point2D
- y
- {Number} The Y coordinate or null if X is a Point2D
setMass(mass)
Set the total mass of the body in kilograms.
- Parameters:
- mass
- {Number} The mass of the body in kg
setPosition(point)
Set the initial position of the body. Once a body is in motion, updating
its position should be avoided since it doesn't fit with physical simulation.
To change an object's position, try applying forces or impulses to the body.
- Parameters:
- point
- {R.math.Point2D} The initial position of the body
setRenderComponent(renderComponent)
Set the associated render component for this body. This is typically used by the
PhysicsActor to link a body to a renderer so that each body can have an
associated renderer applied.
- Parameters:
- renderComponent
- {R.components.Render} The render component to associate with this body
setRestitution(restitution)
Set the resitution (bounciness) of the body. The value should be between
zero and one. Values higher than one are accepted, but produce objects which
are unrealistically bouncy.
- Parameters:
- restitution
- {Number} A value between 0.0 and 1.0
setRotation(angle)
Set the angle of rotation for the body, in degrees.
- Parameters:
- angle
- {Number} The rotation angle in degrees
setStatic(state)
Set a body to be static or dynamic. A static body will not move around.
- Parameters:
- state
- {Boolean}
true
to set the body as static,false
for dynamic.
startSimulation()
Start simulating the body. If the body isn't a part of the simulation,
it is added and simulation occurs. Position and rotation will be updated.
stopSimulation()
Stop simulating the body. If the body is a part of a simulation,
it is removed and simulation stops. The position and rotation of
the body will not be updated.
updateFixture()
Update the fixture on a simulated body. Doing so may cause a hiccup in simulation
wakeUp()
Wake up a body, adding it back into the collection of bodies being simulated.
If the body is not being simulated, this does nothing.