Class R.objects.PhysicsActor
Extends
R.objects.Object2D.
A R.objects.PhysicsActor is an actor object within a game represented by
a collection of components which can include rigid bodies and joints.
Unlike R.objects.Object2D, a R.objects.PhysicsActor
can associate each rigid
body with its own R.components.Render. When the rigid body is updated, the
render component is updated with it. That way, a physics actor can be comprised
of multiple bodies, each with their own renderer allowing for a complex object
such as a ragdoll with many parts and joints. A physics actor is used within a
R.physics.Simulation.
R.objects.PhysicsActor
acts just like an R.objects.Object2D, but it is special
in that it's rigid bodies are animated via a R.physics.Simulation. Without being added to a
R.physics.Simulation, none of the physical bodies will be updated.
Defined in: physicsactor.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.objects.PhysicsActor(name)
Create a physics actor
|
- Fields borrowed from class R.struct.Container:
- EMPTY
Method Attributes | Method Name and Description |
---|---|
add(component, renderComponent)
Add a component to the physics actor.
|
|
destroy()
Remove all of the bodies and joints from the simulation before
destroying the object.
|
|
get(name, objName)
Factory method to create an instance of a physics actor by name.
|
|
Get the class name of this object
|
|
Get the collection of joint components within the actor.
|
|
Get the collection of rigid body components within the actor.
|
|
Get the root body of the R.objects.PhysicsActor.
|
|
Get the
R.physics.Simulation this object participates within. |
|
isReady(name)
Determine the ready state of a physics actor loaded with R.objects.PhysicsActor#load.
|
|
load(name, url)
Helper method to load a physics object file which describes the objects
and joints which comprise the object.
|
|
setPosition(x, y)
Set the position of the actor.
|
|
setRootBody(body)
Set the rigid body component which is considered to be the root
body.
|
|
setSimulation(simulation)
Set the
R.physics.Simulation this actor participates within. |
|
simulate()
Start simulation of the physical components.
|
|
update(renderContext, time, dt)
Update this object within the render context, at the specified timeslice.
|
- Methods borrowed from class R.objects.Object2D:
- deserialize, getAABB, getBoundingBox, getBoundingCircle, getCollisionHull, getDefaultTransformComponent, getLastPosition, getOrigin, getOriginPosition, getPosition, getProperties, getRenderPosition, getRenderRotation, getRotation, getScale, getScaleX, getScaleY, getTransformationMatrix, getWorldBox, getWorldCircle, getZIndex, release, serialize, setBoundingBox, setCollisionHull, setDefaultTransformComponent, setOrigin, setRotation, setScale, setZIndex
- Methods borrowed from class R.engine.GameObject:
- componentSort, getComponent, getComponentByClass, getRenderContext, isDirty, isKeepAlive, markDirty, remove, setKeepAlive, setRenderContext, wasDirty
- Methods borrowed from class R.struct.HashContainer:
- cleanUp, clear, isInHash, removeAtIndex, removeHash
- Methods borrowed from class R.struct.Container:
- addAll, append, clone, concat, contains, filter, forEach, fromArray, getAll, getObjects, insert, iterator, reduce, replace, replaceAt, size, sort, subset, toXML
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, getElement, jQ, removeEvent, setElement, triggerEvent
- Methods borrowed from class R.engine.PooledObject:
- clearObjectDataModel, getId, getName, getObjectDataModel, isDestroyed, setName, setObjectDataModel, toString
Class Detail
R.objects.PhysicsActor(name)
Create a physics actor
- Parameters:
- name
- {String} The name of the actor object
Method Detail
add(component, renderComponent)
Add a component to the physics actor. The components will be
sorted based on their type then their priority within that type.
Components with a higher priority will be sorted before components
with a lower priority. The sorting order for type is:
- Input
- Transform
- Logic
- Collision
- Rendering
- Parameters:
- component
- {R.components.Base} A component to add to the host. If the component is a R.components.physics.BaseBody then the render component must be specified.
- renderComponent Optional
- {R.components.Render} The render component if the component is a R.components.physics.BaseBody
destroy()
Remove all of the bodies and joints from the simulation before
destroying the object.
{R.objects.PhysicsActor}
get(name, objName)
Factory method to create an instance of a physics actor by name.
- Parameters:
- name
- {String} The unique reference name of the actor object
- objName Optional
- {String} The name to assign to the instance when created
- Returns:
- {R.objects.PhysicsActor} A new instance of the actor defined by "name"
{String}
getClassName()
Get the class name of this object
- Returns:
- The string R.objects.PhysicsActor
{Array}
getJoints()
Get the collection of joint components within the actor.
- Returns:
- {Array}
{Array}
getRigidBodies()
Get the collection of rigid body components within the actor.
- Returns:
- {Array}
{R.components.physics.BaseBody}
getRootBody()
Get the root body of the R.objects.PhysicsActor. If no root object has been assigned,
the first rigid body component will be used.
- Returns:
- {R.components.physics.BaseBody}
{R.physics.Simulation}
getSimulation()
Get the
R.physics.Simulation
this object participates within.
- Returns:
- {R.physics.Simulation}
{Boolean}
isReady(name)
Determine the ready state of a physics actor loaded with R.objects.PhysicsActor#load.
- Parameters:
- name
- {String} The unique reference name of the actor object
- Returns:
- {Boolean}
true
if the object is ready for use
load(name, url)
Helper method to load a physics object file which describes the objects
and joints which comprise the object. The format consists of "parts"
which define the types of physical object ("circle", "box") and other
parameters required by each part. Additionally, the format will load
joints which are used to link the parts together.
The actor object is loaded asynchronously which means it isn't immediately
available. You get a reference to the object by calling R.objects.PhysicsActor#get.
An example R.objects.PhysicsActor file can be found in the "/demos/physics2/"
demo game.
- Parameters:
- name
- {String} The unique reference name of the actor object
- url
- {String} The URL where the resource is located
setPosition(x, y)
Set the position of the actor. If the actor is comprised of multiple rigid bodies,
the position will be set for all rigid bodies and joints, relative to the root body.
- Parameters:
- x
- {Number|R.math.Point2D} The X position, or a R.math.Point2D
- y
- {Number} The Y position, or null if X is a R.math.Point2D
setRootBody(body)
Set the rigid body component which is considered to be the root
body. When setting the position of a R.objects.PhysicsActor, all positions
are calculated relative to where the root body was originally set.
It is not necessary to set the root body if there is only one rigid body
in the actor.
- Parameters:
- body
- {R.components.physics.BaseBody} The body to assign as the root
setSimulation(simulation)
Set the
R.physics.Simulation
this actor participates within. When a R.objects.PhysicsActor
is part of a running R.physics.Simulation
, you must set the simulation so the physics components
can be properly added to the simulated world.
- Parameters:
- simulation
- {R.physics.Simulation} The simulation this object is within
simulate()
Start simulation of the physical components.
update(renderContext, time, dt)
Update this object within the render context, at the specified timeslice.
- Parameters:
- renderContext
- {R.rendercontexts.AbstractRenderContext} The context the object will be rendered within.
- time
- {Number} The global time within the engine.
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.