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.
{ // 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.
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 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