Class Index | File Index

Classes


Class R.resources.loaders.SpriteLoader


Extends R.resources.loaders.ImageLoader.
Loads sprite resources and makes them available to the system. Sprites are defined by an external JSON resource file. A sprite definition file is a JSON file which can support single-line comments. The format describes the image which contains the bitmap, the size of the bitmap, the version of the file, and the sprites. Sprites can be either single frames or animations. Animations are expected to be sequentially organized in the bitmap from left to right. Each frame of an animation must be the exact same dimensions.

A frame is simply defined by the upper left corner of the sprite and the width and height of the frame. For an animation, the first four arguments are the same as a frame, followed by the frame count, the millisecond delay between frames, and the type of animation (either "loop" or "toggle"). A looped animation will play all frames, indicated by the frame count, and then start again from the beginning of the animation. A toggled animation will play from the first to the last frame, then play from the last to the first, and then repeat. The first and last frame will not be repeated in a toggled animation. Thus, if the frames are A, B, C, then the toggle will play as A, B, C, B, A, B...

{
   // Sprite definition file v2
   "bitmapImage": "bitmapFile.ext",
   "bitmapSize": [320, 320],
   "version": 2
   "sprites": {
       "stand": [0, 0, 32, 32],
       "walk": [32, 0, 32, 32, 3, 150, "loop"]
   }
}
Note: The new file structure is a bit more compact, and is indicated with the "version" key in the file, set to the value 2. Version 1 will be deprecated and will not be supported in a future release of The Render Engine.
Defined in: spriteloader.js.

Class Summary
Constructor Attributes Constructor Name and Description
 
Fields borrowed from class R.resources.loaders.ImageLoader:
loadAdjust
Fields borrowed from class R.resources.loaders.RemoteLoader:
STATUS_CACHED, STATUS_NOT_FOUND, STATUS_OK, STATUS_SERVER_ERROR
Method Summary
Method Attributes Method Name and Description
 
afterLoad(name, info)
Called after the data has been loaded, passing along the info object and name of the sprite resource.
 
exportAll(resource, spriteNames)
Export all of the sprites in the specified resource, as a JavaScript object, with the sprite name as the key and the corresponding R.resources.types.Sprite as the value.
 
get(name)
Get the sprite resource with the specified name from the cache.
 
Get the class name of this object.
 
The name of the resource this loader will get.
 
getSprite(resource, sprite)
Creates a R.resources.types.Sprite object representing the named sprite.
 
getSpriteNames(resource)
Get the names of all the sprites available in a resource.
 
isReady(name)
Check to see if a named resource is "ready for use".
 
load(name, url)
Load a sprite resource from a URL.
Methods borrowed from class R.resources.loaders.ImageLoader:
getDimensions, getImage, getResourceObject, loadImageResource
Methods borrowed from class R.resources.loaders.RemoteLoader:
exists, getPathUrl, setPathUrl
Methods borrowed from class R.resources.loaders.AbstractResourceLoader:
clear, destroy, getCachedObjects, getResources, release, set, setReady, unload
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.loaders.SpriteLoader(name)
Parameters:
name
{String=SpriteLoader} The name of the resource loader
Method Detail
afterLoad(name, info)
Called after the data has been loaded, passing along the info object and name of the sprite resource.
Parameters:
name
{String} The name of the sprite resource
info
{Object} The sprite resource definition

exportAll(resource, spriteNames)
Export all of the sprites in the specified resource, as a JavaScript object, with the sprite name as the key and the corresponding R.resources.types.Sprite as the value.
Parameters:
resource
{String} The name of the sprite resource
spriteNames Optional
{Array} An optional array of sprites to export, by name, or null to export all sprites

{Object} get(name)
Get the sprite resource with the specified name from the cache. The object returned contains the bitmap as image and the sprite definition as info.
Parameters:
name
{String} The name of the object to retrieve
Returns:
{Object} An object with two keys: "image" and "info"

{String} getClassName()
Get the class name of this object.
Returns:
{String} The string "R.resources.loaders.SpriteLoader"

{String} getResourceType()
The name of the resource this loader will get.
Returns:
{String} The string "sprite"

{R.resources.types.Sprite} getSprite(resource, sprite)
Creates a R.resources.types.Sprite object representing the named sprite.
Parameters:
resource
{String} The name of a loaded sprite resource
sprite
{String} The name of the sprite from the resource
Returns:
{R.resources.types.Sprite} A R.resources.types.Sprite instance

{Array} getSpriteNames(resource)
Get the names of all the sprites available in a resource.
Parameters:
resource
{String} The name of the resource
Returns:
{Array} All of the sprite names in the given loaded resource

{Boolean} isReady(name)
Check to see if a named resource is "ready for use".
Parameters:
name
{String} The name of the resource to check ready status for, or null for all resources in loader.
Returns:
{Boolean} true if the resource is loaded and ready to use

load(name, url)
Load a sprite resource from a URL.
Parameters:
name
{String} The name of the resource
url
{String} The URL where the resource is located

Documentation generated by JsDoc Toolkit 2.4.0 on Mon Mar 18 2013 16:09:20 GMT-0400 (EDT)