Class R.resources.types.Sprite
Extends
R.engine.BaseObject.
A 2D sprite object. Sprites are either a single frame, or an animation composed of
multiple frames run at a specified frame speed. Animations can be run once, loop
continuously, or toggle back and forth through the frames. It is possible to start
and stop animations, and also modify the speed at which each frame is played.
- finished - A "run once" animation has played and completed
- loopRestarted - A looping animation has begun a new cycle
- toggled - A toggle animation has changed animation direction
Defined in: sprite.js.
Constructor Attributes | Constructor Name and Description |
---|---|
R.resources.types.Sprite(name, spriteObj, spriteResource)
|
Field Attributes | Field Name and Description |
---|---|
The sprite animation loops
|
|
The sprite animation plays once from the beginning then stops at the last frame
|
|
The sprite animation toggles - Plays from the first to the last frame
then plays backwards to the first frame and repeats.
|
|
The sprite is an animation
|
|
The sprite is a single frame
|
Method Attributes | Method Name and Description |
---|---|
destroy()
Destroy the sprite instance
|
|
Get the bounding box for the sprite.
|
|
Gets the class name of this object.
|
|
getFrame(time, dt)
Gets the frame of the sprite.
|
|
Get the number of frames in the sprite.
|
|
Get the frame speed of the animation in milliseconds, or -1 if it's a single frame.
|
|
The source image loaded by the SpriteLoader when the sprite was
created.
|
|
getSpeed()
Get the number of milliseconds each frame is displayed for an animation
|
|
Get the sprite loader this sprite originated from
|
|
Get the resource this sprite originated from
|
|
gotoFrame(frameNum)
For animated sprites, go to a particular frame number.
|
|
Returns true if the sprite is an animation.
|
|
isLoop()
Returns true if the sprite is an animation and loops.
|
|
isOnce()
Returns true if the sprite is an animation and plays once.
|
|
isToggle()
Returns true if the sprite is an animation and toggles.
|
|
play()
For animated sprites, play the animation if it is stopped.
|
|
release()
Release the sprite back into the pool for reuse
|
|
reset()
For animated sprites, reset the animation to frame zero.
|
|
setSpeed(speed)
Set the speed, in milliseconds, that an animation runs at.
|
|
stop()
For animated sprites, stop the animation if it is playing.
|
- 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.resources.types.Sprite(name, spriteObj, spriteResource)
- Parameters:
- name
- {String} The name of the sprite within the resource
- spriteObj
- {Object} Passed in by a SpriteLoader. An array which defines the sprite frame, and parameters.
- spriteResource
- {Object} The sprite resource loaded by the SpriteLoader
Field Detail
MODE_LOOP
The sprite animation loops
MODE_ONCE
The sprite animation plays once from the beginning then stops at the last frame
MODE_TOGGLE
The sprite animation toggles - Plays from the first to the last frame
then plays backwards to the first frame and repeats.
TYPE_ANIMATION
The sprite is an animation
TYPE_SINGLE
The sprite is a single frame
Method Detail
destroy()
Destroy the sprite instance
{R.math.Rectangle2D}
getBoundingBox()
Get the bounding box for the sprite.
- Returns:
- {R.math.Rectangle2D} The bounding box which contains the entire sprite
{String}
getClassName()
Gets the class name of this object.
- Returns:
- {String} The string "R.resources.types.Sprite"
{R.math.Rectangle2D}
getFrame(time, dt)
Gets the frame of the sprite. The frame is the rectangle defining what
portion of the image map the sprite frame occupies, given the specified time.
- Parameters:
- time
- {Number} Current world time
- dt
- {Number} The delta between the world time and the last time the world was updated in milliseconds.
- Returns:
- {R.math.Rectangle2D} A rectangle which defines the frame of the sprite in the source image map.
{Number}
getFrameCount()
Get the number of frames in the sprite.
- Returns:
- {Number}
{Number}
getFrameSpeed()
Get the frame speed of the animation in milliseconds, or -1 if it's a single frame.
- Returns:
- {Number}
{HTMLImage}
getSourceImage()
The source image loaded by the SpriteLoader when the sprite was
created.
- Returns:
- {HTMLImage} The source image the sprite is contained within
{Number}
getSpeed()
Get the number of milliseconds each frame is displayed for an animation
- Returns:
- {Number} The milliseconds per frame
{R.resources.loaders.SpriteLoader}
getSpriteLoader()
Get the sprite loader this sprite originated from
- Returns:
- {R.resources.loaders.SpriteLoader}
{Object}
getSpriteResource()
Get the resource this sprite originated from
- Returns:
- {Object}
gotoFrame(frameNum)
For animated sprites, go to a particular frame number.
- Parameters:
- frameNum
- {Number} The frame number to jump to
{Boolean}
isAnimation()
Returns true if the sprite is an animation.
- Returns:
- {Boolean} true if the sprite is an animation
{Boolean}
isLoop()
Returns true if the sprite is an animation and loops.
- Returns:
- {Boolean} true if the sprite is an animation and loops
{Boolean}
isOnce()
Returns true if the sprite is an animation and plays once.
- Returns:
- {Boolean} true if the sprite is an animation and plays once
{Boolean}
isToggle()
Returns true if the sprite is an animation and toggles.
- Returns:
- {Boolean} true if the sprite is an animation and toggles
play()
For animated sprites, play the animation if it is stopped.
release()
Release the sprite back into the pool for reuse
reset()
For animated sprites, reset the animation to frame zero.
setSpeed(speed)
Set the speed, in milliseconds, that an animation runs at. If the sprite is
not an animation, this has no effect.
- Parameters:
- speed
- {Number} The number of milliseconds per frame of an animation
stop()
For animated sprites, stop the animation if it is playing.