Class: AssetLoader

AssetLoader()

new AssetLoader()

Handles loading and storage of game assets.
Source:

Members

loadedCount :number

Type:
  • number
Source:

totalCountInCurrentBatch :number

Type:
  • number
Source:

Methods

get(name) → {HTMLImageElement|object|AudioBuffer|undefined}

Retrieves a pre-loaded asset from the cache.
Parameters:
Name Type Description
name string The name/key of the asset to retrieve.
Source:
Returns:
The cached asset, or undefined if not found.
Type
HTMLImageElement | object | AudioBuffer | undefined

getLoadingCount() → {number}

Gets the current number of assets being loaded.
Source:
Returns:
Type
number

isDoneLoading() → {boolean}

Checks if all assets currently being loaded have finished loading.
Source:
Returns:
True if loadedCount is 0, false otherwise.
Type
boolean

loadAll(batchIdopt) → {Promise.<Map.<string, any>>}

Starts loading all queued assets.
Parameters:
Name Type Attributes Default Description
batchId string <optional>
'defaultBatch' An optional identifier for this loading batch.
Source:
Returns:
A promise that resolves with a map of successfully loaded assets in this batch, or rejects if any critical asset fails (though individual errors are also emitted).
Type
Promise.<Map.<string, any>>

queueAudio(name, path, groupopt) → {this}

Queues an audio file for loading.
Parameters:
Name Type Attributes Default Description
name string A unique name to identify the asset.
path string The path to the audio file.
group string <optional>
'global' An optional group name for the asset.
Source:
Returns:
Type
this

queueImage(name, path, groupopt) → {this}

Queues an image for loading.
Parameters:
Name Type Attributes Default Description
name string A unique name to identify the asset.
path string The path to the image file.
group string <optional>
'global' An optional group name for the asset.
Source:
Returns:
Type
this

queueJSON(name, path, groupopt) → {this}

Queues a JSON file for loading.
Parameters:
Name Type Attributes Default Description
name string A unique name to identify the asset.
path string The path to the JSON file.
group string <optional>
'global' An optional group name for the asset.
Source:
Returns:
Type
this