Create an instance of an AssetRegistry.
The ResourceLoader used to load the asset files.
BundleRegistry
A URL prefix that will be added to all asset loading requests.
Add an asset to the registry.
The asset to add.
Return all Assets that satisfy a filter callback.
The callback function that is used to filter assets.
Return true
to include an asset in the returned array.
A list of all Assets found.
Return all Assets that satisfy the search query. Query can be simply a string, or comma separated strings, to have inclusive results of assets that match at least one query. A query that consists of an array of tags can be used to match assets that have each tag of array.
Rest
...args: anyA list of all Assets matched query.
const assets = app.assets.findByTag("level-1");
// returns all assets that tagged by `level-1`
const assets = app.assets.findByTag("level-1", "level-2");
// returns all assets that tagged by `level-1` OR `level-2`
Fire an event, all additional arguments are passed on to the event listener.
Name of event to fire.
Optional
arg1: anyFirst argument that is passed to the event handler.
Optional
arg2: anySecond argument that is passed to the event handler.
Optional
arg3: anyThird argument that is passed to the event handler.
Optional
arg4: anyFourth argument that is passed to the event handler.
Optional
arg5: anyFifth argument that is passed to the event handler.
Optional
arg6: anySixth argument that is passed to the event handler.
Optional
arg7: anySeventh argument that is passed to the event handler.
Optional
arg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Load the asset's file from a remote source. Listen for "load" events on the asset to find out when it is loaded.
The asset to load.
Optional
options: { Options for asset loading.
A callback that will be called when loading an asset that is contained in any of the bundles. It provides an array of bundles and will ensure asset is loaded from bundle returned from a callback. By default smallest filesize bundle is choosen.
If set to true, then asset will not try to load from a bundle. Defaults to false.
If set to true, then the check of asset being loaded or is already loaded is bypassed, which forces loading of asset regardless.
// load some assets
const assetsToLoad = [
app.assets.find("My Asset"),
app.assets.find("Another Asset")
];
let count = 0;
assetsToLoad.forEach(function (assetToLoad) {
assetToLoad.ready(function (asset) {
count++;
if (count === assetsToLoad.length) {
// done
}
});
app.assets.load(assetToLoad);
});
Use this to load and create an asset if you don't have assets created. Usually you would only use this if you are not integrated with the PlayCanvas Editor.
The url to load.
The type of asset to load.
Function called when asset is loaded, passed (err, asset), where err is null if no errors were encountered.
Use this to load and create an asset when both the URL and filename are required. For example, use this function when loading BLOB assets, where the URL does not adequately identify the file.
The url to load.
The filename of the asset to load.
The type of asset to load.
Function called when asset is loaded, passed (err, asset), where err is null if no errors were encountered.
Detach an event handler from an event. If callback is not provided then all callbacks are unbound from the event, if scope is not provided then all events with the callback will be unbound.
Optional
name: stringName of the event to unbind.
Optional
callback: HandleEventCallbackFunction to be unbound.
Optional
scope: objectScope that was used as the this when the event is fired.
Self for chaining.
const handler = function () {
};
obj.on('test', handler);
obj.off(); // Removes all events
obj.off('test'); // Removes all events called 'test'
obj.off('test', handler); // Removes all handler functions, called 'test'
obj.off('test', handler, this); // Removes all handler functions, called 'test' with scope this
Attach an event handler to an event.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Can be used for removing event in the future.
Attach an event handler to an event. This handler will be removed after being fired once.
Name of the event to bind the callback to.
Function that is called when event is fired. Note the callback is limited to 8 arguments.
Optional
scope: object = ...Object to use as 'this' when the event is fired, defaults to current this.
Remove an asset from the registry.
The asset to remove.
True if the asset was successfully removed and false otherwise.
Static
EVENT_Fired when an asset is added to the registry. This event is available in three forms. They are as follows:
add
- Fired when any asset is added to the registry.add:[id]
- Fired when an asset is added to the registry, where [id]
is the unique id
of the asset.add:url:[url]
- Fired when an asset is added to the registry and matches the URL
[url]
, where [url]
is the URL of the asset.Static
EVENT_Fired when an error occurs during asset loading. This event is available in two forms. They are as follows:
error
- Fired when any asset reports an error in loading.error:[id]
- Fired when an asset reports an error in loading, where [id]
is the
unique id of the asset.Static
EVENT_Fired when an asset completes loading. This event is available in three forms. They are as follows:
load
- Fired when any asset finishes loading.load:[id]
- Fired when a specific asset has finished loading, where [id]
is the
unique id of the asset.load:url:[url]
- Fired when an asset finishes loading whose URL matches [url]
, where
[url]
is the URL of the asset.Static
EVENT_Fired when an asset is removed from the registry. This event is available in three forms. They are as follows:
remove
- Fired when any asset is removed from the registry.remove:[id]
- Fired when an asset is removed from the registry, where [id]
is the
unique id of the asset.remove:url:[url]
- Fired when an asset is removed from the registry and matches the
URL [url]
, where [url]
is the URL of the asset.
Container for all assets that are available to this application. Note that PlayCanvas scripts are provided with an AssetRegistry instance as
app.assets
.