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. |
Example
var assetLibrary = new HX.AssetLibrary("assets/");assetLibrary.queueAsset("some-model", "models/some-model.obj", HX.AssetLibrary.Type.ASSET, HX.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.JSON
for a JSON object.Properties:
Name Type Default Description JSON
0 A JSON data object.
ASSET
1 An asset.
PLAIN_TEXT
2 A plain text file.
RAW_BINARY
3 Raw binary data
-
basePath
-
The base path relative to which all the filenames are defined. This value is set in the constructor.
-
crossOrigin
-
The cross origin string passed to the constructor.
-
onComplete
-
The
Signal
dispatched when all assets have completed loading. Its payload object is a reference to the assetLibrary itself.- See:
-
onProgress
-
The
Signal
dispatched when all assets have completed loading. Its payload is the ratio of loaded objects for 0 to 1.- See:
Methods
-
addAsset(id, asset)
-
Adds an asset explicitly.
Parameters:
Name Type Description id
string The ID assigned to the asset when calling
get
asset
The asset to add to the library
-
get(id)
-
Retrieves a loaded asset from the asset library. This method should only be called once
onComplete
has been dispatched.Parameters:
Name Type Description id
string The ID assigned to the loaded asset when calling
queueAsset
Returns:
The loaded asset.
- Type
- *
-
load()
-
Start loading all the assets. Every time a single asset finished loading,
onProgress
is dispatched. When all assets have finished loading,onComplete
is dispatched. -
mergeLibrary(library)
-
Merges the contents of another library into the current.
Parameters:
Name Type Description library
AssetLibrary The library to add.
-
queueAsset(id, file, type, parser [, options] [, target])
-
Adds an asset to the loading queue.
Parameters:
Name Type Argument Description id
string The ID that will be used to retrieve the asset when loaded.
file
string Either a File object or a filename relative to the base path provided in the constructor.
type
AssetLibrary.Type The type of asset to be loaded.
parser
The 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