Class R.components.Base
Extends
R.engine.BaseObject.
All components extend from this object class. A component is one
part of an operating whole object (a R.engine.GameObject) which is
responsible for only a portion of the overall operation of the
game object. Components are broken down into five major categories:
- TYPE_INPUT - Input from controllers (keyboard, mouse, etc.)
- TYPE_TRANSFORM - Performs transformations on the host object
- TYPE_LOGIC - Handles logical operations that are not related to input and collision
- TYPE_COLLIDER - Determines what this object is possibly colliding with, and reports those collisions via callbacks to the host.
- TYPE_RENDERING - Performs some sort of rendering operation to the context
Defined in: base.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.components.Base(name, type, priority)
Create a new instance of a component, setting the name, type, and
update priority of this component compared to all other components
within the host.
|
Field Attributes | Field Name and Description |
---|---|
The constant value for COLLIDER components.
|
|
The constant value for INPUT components.
|
|
The constant value for LOGIC components.
|
|
The constant value for RENDERING components.
|
|
The constant value for TRANSFORM (movement) components.
|
Method Attributes | Method Name and Description |
---|---|
execute(renderContext, time, dt)
[ABSTRACT] This method is called by the game object to run the component,
updating its state.
|
|
Get the class name of this object
|
|
Gets the game object this component is a part of.
|
|
Deprecated in favor of #getGameObject
|
|
Returns the priority of this component.
|
|
getType()
Get the type of this component.
|
|
Get the type of the component as a string.
|
|
release()
Releases the object back into the object pool.
|
|
setGameObject(gameObject)
Establishes the link between this component and its game object.
|
|
setHostObject(hostObject)
Deprecated in favor of #setGameObject
|
|
setPriority(priority)
Set the execution priority of this component with
1.0 being the highest priority and 0.0 being the lowest.
|
- Methods borrowed from class R.engine.BaseObject:
- addEvent, addEvents, destroy, 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.Base(name, type, priority)
Create a new instance of a component, setting the name, type, and
update priority of this component compared to all other components
within the host.
- Parameters:
- name
- {String} The name of the component
- type
- {Number} The type of the component
- priority
- {Number} A value between 0.0 and 1.0. Default: 0.5
Field Detail
TYPE_COLLIDER
The constant value for COLLIDER components.
TYPE_INPUT
The constant value for INPUT components.
TYPE_LOGIC
The constant value for LOGIC components.
TYPE_RENDERING
The constant value for RENDERING components.
TYPE_TRANSFORM
The constant value for TRANSFORM (movement) components.
Method Detail
execute(renderContext, time, dt)
[ABSTRACT] This method is called by the game object to run the component,
updating its state. Not all components will need an execute
method. However, it is important to include one if you need to
update the state of the component for each engine cycle.
- Parameters:
- renderContext
- {R.rendercontexts.AbstractRenderContext} The context the component will render within.
- time
- {Number} The global engine time
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
{String}
getClassName()
Get the class name of this object
- Returns:
- {String} The string "R.components.Base"
{R.engine.GameObject}
getGameObject()
Gets the game object this component is a part of. When the component was
assigned to a game object, the game object will have set itself as the container
via #setGameObject.
- Returns:
- {R.engine.GameObject}
getHostObject()
Deprecated in favor of #getGameObject
{Number}
getPriority()
Returns the priority of this component.
- Returns:
- {Number} A value between 0.0 and 1.0
{Number}
getType()
Get the type of this component. The value will be one of:
#TYPE_INPUT, #TYPE_TRANSFORM, #TYPE_LOGIC,
#TYPE_COLLIDER, or #TYPE_RENDERING
- Returns:
- {Number} The component type Id
{String}
getTypeString()
Get the type of the component as a string.
- Returns:
- {String}
release()
Releases the object back into the object pool. See PooledObject#release
for more information.
setGameObject(gameObject)
Establishes the link between this component and its game object.
When you assign components to a game object, it will call this method
so that each component can refer to its game object, the same way
a game object can refer to a component with R.engine.GameObject#getComponent.
- Parameters:
- gameObject
- {R.engine.GameObject} The object which hosts this component
setHostObject(hostObject)
Deprecated in favor of #setGameObject
- Parameters:
- hostObject
setPriority(priority)
Set the execution priority of this component with
1.0 being the highest priority and 0.0 being the lowest. Components
within a game object are sorted by type, and then priority. As such,
two components with the same type will be sorted by priority with the
higher value executing before the lower value. This allows you to layer
components like the R.components.Render component so that one effect
is drawn before another.
- Parameters:
- priority
- {Number} A value between 0.0 and 1.0