Class R.objects.SpriteActor
Extends
R.objects.Object2D.
A SpriteActor is an actor object within a game, whose renderer
is a 2D sprite. It can have actions assigned to it, which are triggered
by either a controlling player or generated by the program.
Defined in: spriteactor.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.objects.SpriteActor(name)
Create a sprite actor
|
- Fields borrowed from class R.struct.Container:
- EMPTY
Method Attributes | Method Name and Description |
---|---|
deserialize(obj, spriteLoaders, clazz)
Deserialize the object back into a sprite actor.
|
|
destroy()
Destroy the object
|
|
Get the actor's unique Id which references this object
|
|
Get the class name of this object
|
|
Get the collision bitmask for this object
|
|
Get the events object for this actor.
|
|
Check to see if this actor is affected by gravity.
|
|
Get a properties object for this sprite actor
|
|
Get the sprite which represents this actor
|
|
getVariable(varName)
Get the value of the specified variable.
|
|
Returns true if the actor can be collided with
|
|
onCollide(collisionObj, time, dt, targetMask)
Host callback which is triggered when collision occurs between this object and
another object.
|
|
release()
Release the object back into the pool.
|
|
serialize(actor, defaults)
Serialize the sprite actor into an object.
|
|
setActorId(actorId)
Set the actor's Id which can be looked up with R.objects.SpriteActor#findActor
|
|
setCollidable(state)
Set a flag which will determine if the actor will collide with anything
|
|
setCollisionMask(collisionMask)
Set the collision bitmask for this object
|
|
setGravityFlag(state)
Set a flag indicating that this actor is affected by gravity.
|
|
setSprite(sprite)
Set the sprite which represents this actor
|
|
setVariable(varName, value)
Set the value of the specified variable.
|
|
update(renderContext, time, dt)
Update the player within the rendering context.
|
- Methods borrowed from class R.objects.Object2D:
- getAABB, getBoundingBox, getBoundingCircle, getCollisionHull, getDefaultTransformComponent, getLastPosition, getOrigin, getOriginPosition, getPosition, getRenderPosition, getRenderRotation, getRotation, getScale, getScaleX, getScaleY, getTransformationMatrix, getWorldBox, getWorldCircle, getZIndex, setBoundingBox, setCollisionHull, setDefaultTransformComponent, setOrigin, setPosition, setRotation, setScale, setZIndex
- Methods borrowed from class R.engine.GameObject:
- add, componentSort, getComponent, getComponentByClass, getRenderContext, isDirty, isKeepAlive, markDirty, remove, setKeepAlive, setRenderContext, wasDirty
- Methods borrowed from class R.struct.HashContainer:
- cleanUp, clear, get, 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.SpriteActor(name)
Create a sprite actor
- Parameters:
- name
- {String} The name of the object
Method Detail
{R.objects.SpriteActor}
deserialize(obj, spriteLoaders, clazz)
Deserialize the object back into a sprite actor.
- Parameters:
- obj
- {Object} The object to deserialize
- spriteLoaders
- {Array} An array of sprite loaders
- clazz Optional
- {Class} The object class to populate
- Returns:
- {R.objects.SpriteActor} The object which was deserialized
destroy()
Destroy the object
{String}
getActorId()
Get the actor's unique Id which references this object
- Returns:
- {String}
{String}
getClassName()
Get the class name of this object
- Returns:
- The string R.objects.SpriteActor
{String}
getCollisionMask()
Get the collision bitmask for this object
- Returns:
- {String}
{Object}
getConfig()
Get the events object for this actor. The configuration is a
collection of variables and scripts which are used to run the actor. When
scripts are called, the scope of the callback is the actor. The following are
included:
- onInit() - Called when the actor is added to the level
- onDestroy() - Called when the actor is removed from the level
- onCollide(collisionData, targetMask, worldTime) - Called when the actor collides with another object. The data contains information about the collision. See: R.struct.CollisionData The mask is the target's collision bitmask, and the time is the world time when the collision occurred.
- onVisibility(state) - Called when the actor enters or leaves the frame. The state will be true when visible (rendered).
- onBeforeUpdate(worldTime) - Called before the actor is updated, providing the world time.
- onAfterUpdate(worldTime) - Called after the actor is updated, providing the world time.
- Returns:
- {Object}
{Boolean}
getGravityFlag()
Check to see if this actor is affected by gravity.
- Returns:
- {Boolean}
{Object}
getProperties()
Get a properties object for this sprite actor
- Returns:
- {Object}
{R.resources.types.Sprite}
getSprite()
Get the sprite which represents this actor
- Returns:
- {R.resources.types.Sprite}
{Object}
getVariable(varName)
Get the value of the specified variable.
- Parameters:
- varName
- {String}
- Returns:
- {Object} The value of the variable
{Boolean}
isCollidable()
Returns true if the actor can be collided with
- Returns:
- {Boolean}
{Number}
onCollide(collisionObj, time, dt, targetMask)
Host callback which is triggered when collision occurs between this object and
another object. This will typically trigger an event callback for scripted events.
- Parameters:
- collisionObj
- {R.objects.Object2D} The object that this object collided with
- time
- {Number} The time at which the collision occurred
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
- targetMask
- {Number} The collision mask for the object this collided with
- Returns:
- {Number} Returns a flag which tells the collision system what to do
release()
Release the object back into the pool.
{Object}
serialize(actor, defaults)
Serialize the sprite actor into an object.
- Parameters:
- actor
- {R.engine.SpriteActor} The object to serialize
- defaults Optional
- {Object} Default values that don't need to be serialized unless they are different.
- Returns:
- {Object}
setActorId(actorId)
Set the actor's Id which can be looked up with R.objects.SpriteActor#findActor
- Parameters:
- actorId
- {String} A unique Id to reference this object
setCollidable(state)
Set a flag which will determine if the actor will collide with anything
- Parameters:
- state
- {Boolean} true to collide with other objects
setCollisionMask(collisionMask)
Set the collision bitmask for this object
- Parameters:
- collisionMask
- {String} A binary string of ones and zeros
setGravityFlag(state)
Set a flag indicating that this actor is affected by gravity.
- Parameters:
- state
- {Boolean}
true
to enable gravity on this actor
setSprite(sprite)
Set the sprite which represents this actor
- Parameters:
- sprite
- {R.resources.types.Sprite} The sprite
setVariable(varName, value)
Set the value of the specified variable.
- Parameters:
- varName
- {String} The name of the variable
- value
- {Object} The value to assign to the variable
update(renderContext, time, dt)
Update the player within the rendering context. This draws
the shape to the context, after updating the transform of the
object. If the player is thrusting, draw the thrust flame
under the ship.
- 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.