API Docs for:
Show:

AssetManager Class

This class is responsible for loading, unloading and managing the life time of assets. It uses reference counting to ensure that only one instance of a particular asset is loaded at a time. The asset manager will trigger events. "assetLoaded" event is triggered when an asset is downloaded, this event doesn't trigger if an asset's reference count is incremented. "assetUnloaded" event is triggered when an asset's reference count drops to 0 and thus gets unloaded. "errorLoadingAsset" event is triggered when an asset could not be loaded for any reason. "finishedLoading" event is triggered when all asset requests passed in the load function have been processed, for more information see the load function.

Constructor

AssetManager

()

Item Index

Properties

Methods

get

(
  • assetPath
)
AssetHandle

Parameters:

  • assetPath String

    Path of the asset to be retrieved.

Returns:

AssetHandle: The handle for the requested asset.

load

(
  • assetPath
)
Number

Parameters:

  • assetPath String | Array multiple

    An array of strings or one or more strings representing paths of assets to be loaded.

Returns:

Number: A unique id for this load request. Once the loading is finished, a "finishedLoading" event will be triggered. To identify which load request it corresponds to, the event data will be this id.

Example:

   assetManager.load('music.mp3', 'sprite.png');
   var array = ['music.mp3', 'sprite.png'];
   assetManager.load(array);

subscribe

(
  • event
  • callback
  • [subscriber]
)

Parameters:

  • event String

    Name of the event being subscribed to.

  • callback Function

    Function that will be called back when the specified event is triggered.

  • [subscriber] Object optional

    An optional parameter that specifies an object that's subscribing. When a function is subscribed with an object, that function will be called back with "this" set to the object.

trigger

(
  • event
  • [eventObject]
)

Triggers the event, calling all functions that subscribed to it.

Parameters:

  • event String

    The event to be triggered.

  • [eventObject] Object optional

    All functions that were subscribed to the specified event will be called with this as the argument.

unload

(
  • assetPath
)

Parameters:

  • assetPath String or Array multiple

    An array of strings or one or more strings representing paths of assets to be unloaded.

Example:

   assetManager.unload('music.mp3', 'sprite.png');
   var array = ['music.mp3', 'sprite.png'];
   assetManager.unload(array);

unsubscribe

(
  • event
  • [callback]
  • [subscriber]
)

This is a multi-purpose method. See the example for all the ways it can be overloaded.

Parameters:

  • event Object
  • [callback] Object optional
  • [subscriber] Object optional

Example:

   //Unsubscribing all callbacks for a given event.
  eventHandler.unsubscribe('eventName');

  //Unsubscribing all callbacks subscribed by the object.
  eventHandler.unsubscribe(object);

  //Unsubscribing all callbacks an object made for the given event.
  eventHandler.unsubscribe('eventName', object);

  //Unsubscribing a callback that was subscribed with an object.
  eventHandler.unsubscribe('eventName', callback, object);

  //Unsubscribing a callback subscribed by itself.
  eventHandler.unsubscribe('eventName', callback);
  //The last method can't be used to unsubscribe callbacks which were subscribed with an object.

Properties

assetDownloader

AssetDownloader

This is the object that the manager uses to download assets. The manager sets default image and audio types. If those happen to be insufficient, they need to be changed directly in the file.