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.
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 the first Asset with the specified name and type found in the registry.
The name of the Asset to find.
Optionaltype: stringThe type of the Asset to find.
A single Asset or null if no Asset is found.
Return all Assets with the specified name and type found in the registry.
The name of the Assets to find.
Optionaltype: stringThe type of the Assets to find.
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.
A 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.
Optionalarg1: anyFirst argument that is passed to the event handler.
Optionalarg2: anySecond argument that is passed to the event handler.
Optionalarg3: anyThird argument that is passed to the event handler.
Optionalarg4: anyFourth argument that is passed to the event handler.
Optionalarg5: anyFifth argument that is passed to the event handler.
Optionalarg6: anySixth argument that is passed to the event handler.
Optionalarg7: anySeventh argument that is passed to the event handler.
Optionalarg8: anyEighth argument that is passed to the event handler.
Self for chaining.
Retrieve an asset from the registry by its id field.
The id of the asset to get.
The asset.
Retrieve an asset from the registry by its file's URL field.
The url of the asset to get.
The asset.
Test if there are any handlers bound to an event name.
The name of the event to test.
True if the object has handlers bound to the specified event name.
Create a filtered list of assets from the registry.
Properties to filter on, currently supports: 'preload: true|false'.
The filtered list of assets.
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.
Optionaloptions: {Options for asset loading.
OptionalbundlesFilter?: BundlesFilterCallbackA 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.
OptionalbundlesIgnore?: booleanIf set to true, then asset will not try to load from a bundle. Defaults to false.
Optionalforce?: booleanIf 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.
Optionalname: stringName of the event to unbind.
Optionalcallback: HandleEventCallbackFunction to be unbound.
Optionalscope: anyScope 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.
Optionalscope: any = ...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.
Optionalscope: any = ...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.
StaticEVENT_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.StaticEVENT_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.StaticEVENT_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.StaticEVENT_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.