Class AssetManager extends MessageDispatcher

Responsible for loading assets and manages its in memory state.

Methods

AssetManager() constructor
Creates new AssetManager instance. AssetManager exposes static property
called 'default' and many internal classes uses default instance.
setAssetType(name, type) method

Sets asset type. You can use this method to override Asset with your own.

Parameters
name : stringtype : string
setLoaderType(name, type) method

Sets loader type. Use this method to override default loaders with custom ones.

Parameters
name : stringtype : string
enqueueAsset(name, asset) method

Adds asset into the loading queue.

Parameters
name : stringasset : Asset
Returns
void
addTexture(name, texture) method

Adds or changes texture to the internal list for future reuse by given name.

Parameters
name : stringtexture : Texture
enqueueImage(name, url) method

Adds single image to the loading queue.

Parameters
name : string — Name of the asset.
url : string — The URL of the image.
Returns
void
enqueueAtlas(name, imageUrl, dataUrl) method

Adds atlas to the loading queue.

Parameters
name : string — Name of the asset.
imageUrl : string — Atlas URL.
dataUrl : string — URL to the .json file which describes the atlas.
Returns
void
enqueueBitmapFont(name, imageUrl, xmlUrl) method

Adds bitmap font to the loading queue.

Parameters
name : string — Name of the font.
imageUrl : string — Image URL.
xmlUrl : string — URL to the .xml file which describes the font.
Returns
void
enqueueXML(name, url) method

Adds single xml file to the loading queue.

Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returns
void
enqueueJSON(name, url) method

Adds single json file to the loading queue.

Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returns
void
enqueueVector(name, url) method

Adds single Black Vector Graphics file to the loading queue.

Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returns
void
enqueueVectorTexture(name, url, bakeSelf, bakeChildren, namesToBake) method

Adds single Black Vector Graphics file to the loading queue and bakes it into the Texture.

If baked both graphics data and baked texture will be stored inside this AssetManager.

Parameters
name : string — Name of the asset.
url : string — The URL of the json.
bakeSelf : boolean — Flag to bake full BVG as texture. If false root will not be baked.
bakeChildren : boolean — Flag to bake each node with id to textures. If false none children nodes will be baked.
namesToBake : Array.<string> — Concrete nodes ids to bake. Works only if bakeChildren is set to true.
Returns
void
enqueueSound(name, url) method

Adds single sound to the loading queue.

Parameters
name : string — Name of the sound.
url : string — The URL of the sound.
Returns
void
enqueueSoundAtlas(name, soundUrl, dataUrl) method

Adds sound atlas to the loading queue.

Parameters
name : string — Name of the sound.
soundUrl : string — The URL of the sound.
dataUrl : string — The URL of the data JSON.
Returns
void
enqueueFont(name, url) method

Adds local font to the loading queue.

Parameters
name : string — Name of the asset.
url : string — The URL to the font.
Returns
void
enqueueGoogleFont(name) method

Adds Google Font to the loading queue.

Parameters
name : string — Name of the asset.
Returns
void
loadQueue() method
Starts loading all enqueued assets.
getBitmapFont(name) method

Returns BitmapFontData object by given name.

Parameters
name : string — The name of the Asset to search.
Returns
BitmapFontData | null — Returns a BitmapFontData if found or null.
getTexture(name) method

Returns Texture object by given name.

Parameters
name : string — The name of the Asset.
Returns
Texture | null — Returns a Texture if found or null.
getGraphicsData(name) method

Returns Graphics data by given name.

Parameters
name : string
Returns
GraphicsData
getTextures(nameMask) method

Returns array of Texture by given name mask.
Searches across all loaded images and atlases.

Parameters
nameMask : string — The name mask.
Returns
Array. | null
getAtlas(name) method

Returns AtlasTexture by given name.

Parameters
name : string — The name of the Asset.
Returns
AtlasTexture | null — Returns atlas or null.
getSound(name) method

Returns SoundClip by given name.

Parameters
name : string — The name of the sound.
Returns
SoundClip — Returns sound or null.
getSoundAtlas(name) method

Returns SoundAtlasClip by given name.

Parameters
name : string — The name of the sound.
Returns
SoundClip — Returns sound or null.
getJSON(name) method

Returns Object parsed from JSON by given name.

Parameters
name : string — The name of the JSON asset.
Returns
Object — Returns object or null.
getCustomAsset(type, name) method

Returns Object parsed from CutsomAsset by given name.

Parameters
type : string — The type of the asset.
name : string — The name of the asset.
Returns
Object | null — Returns object or null.
dispose() method
Destroys all loaded resources.

Inherited Methods

on(name, callback, context) inherited method

Adds listener by given name and callback.

Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as this in callback function.
Returns
MessageBinding
off(names) inherited method

Removes all bindings by given message name.

Parameters
names : string — One or more message name.
Returns
void
once(name, callback, context) inherited method

Adds listener by given name and callback. Binding will be automatically removed after first execution.

Parameters
name : string — Message name.
callback : function — Function to be called on message send.
context : * — Object to be used as this in callback function.
Returns
MessageBinding
post(name, params) inherited method

Posts message with a given params.

Adding ~ character to the begging of the name will bubble message to the top of the tree.

Parameters
name : string — The name of a message
params : * — A list of params to send
Returns
void

Properties

defaultPath : string property
Gets/Sets default path for loading. Useful when URLs getting too long.
The asset path will be concatenated with defaultPath.
isAllLoaded : boolean property
Returns True if all assets were loaded.
numErrors : number property
Returns number of errors occurred during loading.
state : AssetManagerState property
Returns current state.

Inherited Properties

parent : MessageDispatcher | null inherited property
Returns parent MessageDispatcher.
stage : Stage | null inherited property
Returns the stage Game Object to which this belongs to or null if not added onto stage.
path : string | null inherited property
Returns string representing a url like path to this object in the display
tree.