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.
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
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
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.
Adds asset into the loading queue.
addTexture(name, texture) method
Adds or changes texture to the internal list for future reuse by given name.
Adds or changes texture to the internal list for future reuse by given name.
enqueueImage(name, url) method
Adds single image to the loading queue.
Parameters
void
Adds single image to the loading queue.
Parameters
name : string — Name of the asset.
url : string — The URL of the image.
Returnsurl : string — The URL of the image.
void
enqueueAtlas(name, imageUrl, dataUrl) method
Adds atlas to the loading queue.
Parameters
void
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.
ReturnsimageUrl : string — Atlas URL.
dataUrl : string — URL to the .json file which describes the atlas.
void
enqueueBitmapFont(name, imageUrl, xmlUrl) method
Adds bitmap font to the loading queue.
Parameters
void
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.
ReturnsimageUrl : string — Image URL.
xmlUrl : string — URL to the .xml file which describes the font.
void
enqueueXML(name, url) method
Adds single xml file to the loading queue.
Parameters
void
Adds single xml file to the loading queue.
Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returnsurl : string — The URL of the json.
void
enqueueJSON(name, url) method
Adds single json file to the loading queue.
Parameters
void
Adds single json file to the loading queue.
Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returnsurl : string — The URL of the json.
void
enqueueVector(name, url) method
Adds single Black Vector Graphics file to the loading queue.
Parameters
void
Adds single Black Vector Graphics file to the loading queue.
Parameters
name : string — Name of the asset.
url : string — The URL of the json.
Returnsurl : string — The URL of the json.
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
void
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.
Returnsurl : 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.
void
enqueueSound(name, url) method
Adds single sound to the loading queue.
Parameters
void
Adds single sound to the loading queue.
Parameters
name : string — Name of the sound.
url : string — The URL of the sound.
Returnsurl : string — The URL of the sound.
void
enqueueSoundAtlas(name, soundUrl, dataUrl) method
Adds sound atlas to the loading queue.
Parameters
void
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.
ReturnssoundUrl : string — The URL of the sound.
dataUrl : string — The URL of the data JSON.
void
enqueueFont(name, url) method
Adds local font to the loading queue.
Parameters
void
Adds local font to the loading queue.
Parameters
name : string — Name of the asset.
url : string — The URL to the font.
Returnsurl : string — The URL to the font.
void
enqueueGoogleFont(name) method
Adds Google Font to the loading queue.
Parameters
void
Adds Google Font to the loading queue.
Parameters
name : string — Name of the asset.
Returnsvoid
loadQueue() method
Starts loading all enqueued assets.
Starts loading all enqueued assets.
getBitmapFont(name) method
Returns BitmapFontData object by given name.
Parameters
BitmapFontData | null — Returns a BitmapFontData if found or null.
Returns BitmapFontData object by given name.
Parameters
name : string — The name of the Asset to search.
ReturnsBitmapFontData | null — Returns a BitmapFontData if found or null.
getTexture(name) method
Returns Texture object by given name.
Parameters
Texture | null — Returns a Texture if found or null.
Returns Texture object by given name.
Parameters
name : string — The name of the Asset.
ReturnsTexture | null — Returns a Texture if found or null.
getGraphicsData(name) method
Returns Graphics data by given name.
Returns Graphics data by given name.
getTextures(nameMask) method
Returns array of Texture by given name mask.
Searches across all loaded images and atlases.
Parameters
Array. | null
Returns array of Texture by given name mask.
Searches across all loaded images and atlases.
Parameters
nameMask : string — The name mask.
ReturnsArray.
getAtlas(name) method
Returns AtlasTexture by given name.
Parameters
AtlasTexture | null — Returns atlas or null.
Returns AtlasTexture by given name.
Parameters
name : string — The name of the Asset.
ReturnsAtlasTexture | null — Returns atlas or null.
getJSON(name) method
Returns Object parsed from JSON by given name.
Parameters
Object — Returns object or null.
Returns Object parsed from JSON by given name.
Parameters
name : string — The name of the JSON asset.
ReturnsObject — Returns object or null.
getCustomAsset(type, name) method
Returns Object parsed from
Parameters
Object | null — Returns object or null.
Returns Object parsed from
CutsomAsset
by given name.
Parameters
type : string — The type of the asset.
name : string — The name of the asset.
Returnsname : string — The name of the asset.
Object | null — Returns object or null.
dispose() method
Destroys all loaded resources.
Destroys all loaded resources.
Inherited Methods
on(name, callback, context) inherited method
Adds listener by given name and callback.
Parameters
MessageBinding
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
Returnscallback : function — Function to be called on message send.
context : * — Object to be used as
this
in callback function. MessageBinding
off(names) inherited method
Removes all bindings by given message name.
Parameters
void
Removes all bindings by given message name.
Parameters
names : string — One or more message name.
Returnsvoid
once(name, callback, context) inherited method
Adds listener by given name and callback. Binding will be automatically removed after first execution.
Parameters
MessageBinding
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
Returnscallback : function — Function to be called on message send.
context : * — Object to be used as
this
in callback function. MessageBinding
post(name, params) inherited method
Posts message with a given params.
Adding
Parameters
void
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
Returnsparams : * — A list of params to send
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.
Gets/Sets default path for loading. Useful when URLs getting too long.
The asset path will be concatenated with defaultPath.
Inherited Properties
stage : Stage | null inherited property
Returns the stage Game Object to which this belongs to or null if not added onto stage.
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.
Returns string representing a url like path to this object in the display
tree.