new AssetLibrary(basePath [, crossOrigin])
Parameters:
| Name | Type | Argument | Description |
|---|---|---|---|
basePath |
string | The base path or url to load the assets from. All filenames will have this value prepended. |
|
crossOrigin |
string |
<optional> |
An optional cross origin string. This is used when loading images from a different domain. |
Properties:
| Name | Type | Description |
|---|---|---|
onComplete |
Signal | The |
onProgress |
Signal | The |
basePath |
string | The base path relative to which all the filenames are defined. This value is set in the constructor. |
crossOrigin |
string | A cross origin string. This is used when loading images from a different domain. |
Example
var assetLibrary = new HX.AssetLibrary("assets/");
assetLibrary.queueAsset("some-model", "models/some-model.obj", HX.AssetLibrary.Type.ASSET, HX_IO.OBJ);
assetLibrary.queueAsset("some-texture", "textures/some_texture.png", HX.AssetLibrary.Type.ASSET, HX.PNG);
assetLibrary.onComplete.bind(onAssetsLoaded);
assetLibrary.onProgress.bind(onAssetsProgress);
assetLibrary.load();
function onAssetsLoaded()
{
// do something
}
function onAssetsProgress(ratio)
{
var percent = ratio * 100
}
Members
-
<static> Type
-
The type of asset to load. For example:
AssetLibrary.Type.JSONfor a JSON object.Properties:
Name Type Default Description JSON0 A JSON data object.
ASSET1 A Helix-based asset.
PLAIN_TEXT2 A plain text file.
RAW_BINARY3 Raw binary data
Methods
-
addAsset(id, asset)
-
Adds an asset explicitly.
Parameters:
Name Type Description idstring The ID assigned to the asset when calling
getassetThe asset to add to the library
-
get(id)
-
Retrieves a loaded asset from the asset library. This method should only be called once
onCompletehas been dispatched.Parameters:
Name Type Description idstring The ID assigned to the loaded asset when calling
queueAssetReturns:
The loaded asset.
- Type
- *
-
load()
-
Start loading all the assets. Every time a single asset finished loading,
onProgressis dispatched. When all assets have finished loading,onCompleteis dispatched. -
mergeLibrary(library)
-
Merges the contents of another library into the current.
Parameters:
Name Type Description libraryAssetLibrary The library to add.
-
queueAsset(id, file, type, parser [, options] [, target])
-
Adds an asset to the loading queue.
Parameters:
Name Type Argument Description idstring The ID that will be used to retrieve the asset when loaded.
filestring Either a File object or a filename relative to the base path provided in the constructor.
typeAssetLibrary.Type The type of asset to be loaded.
parserThe parser used to parse the loaded data.
options<optional>
An optional options object (importer-dependent)
target<optional>
An optional empty target to contain the parsed asset. This allows lazy loading.
- See:
-
AssetLibrary#Type