Module: assets

Low-level resource loader. In order to load exported scenes, use the data module instead.

Summary

Members

Methods

Type Definitions

Detailed Description

Members

AT_ARRAYBUFFER

Asset type intended for loading various binary data. The loaded data will be available as an ArrayBuffer object. Supported request methods: "GET".
Type:
Source:

AT_ARRAYBUFFER_ZIP

Asset type intended for loading compressed binary data of a GZIP format. The loaded data will be available as an ArrayBuffer object. Supported request methods: "GET".
Type:
Source:

AT_AUDIO_ELEMENT

Asset type intended for loading common audio files. The loaded data will be available as an HTMLAudioElement object. Supported request methods: "GET".
Type:
Source:

AT_AUDIOBUFFER

Asset type intended for loading audio files (preferably short audio assets). The loaded data will be available as an AudioBuffer object. Supported request methods: "GET".
Type:
Source:

AT_IMAGE_ELEMENT

Asset type intended for loading common image files (JPEG, PNG, GIF). The loaded data will be available as an HTMLImageElement object. Supported request methods: "GET".
Type:
Source:

AT_JSON

Asset type intended for loading JSON files. The loaded data will be available as a JSON object. Supported request methods: "GET", "POST".
Type:
Source:

AT_JSON_ZIP

Asset type intended for loading JSON files compressed in a GZIP format. The loaded data will be available as a JSON object. Supported request methods: "GET".
Type:
Source:

AT_SEQ_VIDEO_ELEMENT

Asset type intended for loading video files of a special ".seq" format. The loaded data will be available as an object of the following structure: { images: [HTMLImageElement, ...], fps: number }. Supported request methods: "GET".
Type:
Source:
See:

AT_TEXT

Asset type intended for loading files with a plain text. The loaded data will be available as a String object. Supported request methods: "GET", "POST".
Type:
Source:

AT_VIDEO_ELEMENT

Asset type intended for loading common video files. The loaded data will be available as an HTMLVideoElement object. Supported request methods: "GET".
Type:
Source:

Methods

enqueue(assets_pack, asset_cbopt, pack_cbopt, progress_cbopt)

Add the assets to the loading queue.
Parameters:
Name Type Attributes Description
assets_pack Array.<module:assets~AssetRequest> Array of the asset requests.
asset_cb AssetCallback <optional>
Callback executed after a single asset is loaded
pack_cb PackCallback <optional>
Callback executed after the whole pack of assets is loaded
progress_cb ProgressCallback <optional>
Callback for the progress of loading.
Source:
Example
var m_assets = require("assets");

var asset_cb = function(data, id, type, url) {
     console.log("LOADED:", url);
}

var pack_cb() {
     console.log("ALL DATA LOADED!");
}

var progress_cb = function(rate) {
     console.log(rate * 100 + "% LOADED");
}

m_assets.enqueue([
     {id: "my_json001", type: m_assets.AT_JSON, url: "./my_json.json"}, 
     {id: "my_img001", type: m_assets.AT_IMAGE_ELEMENT, url: "./my_image.jpg"}
     ], asset_cb, pack_cb, progress_cb);

Type Definitions

AssetCallback(data, id, type, url, opt_paramopt)

Callback executed after a single asset is loaded.
Parameters:
Name Type Attributes Description
data Data Loaded data.
id * Data asset ID.
type AssetType Data type.
url string URL of a resource.
opt_param * <optional>
Optional parameter
Source:

AssetRequest

An object that defines how the asset resource should be loaded.
Type:
  • Object
Properties:
Name Type Attributes Default Description
id * Asset identifier. Passed to the module:assets~AssetCallback as a parameter. Can be unique to distinguish asset requests if needed.
type AssetType Asset type.
url string URL of a resource.
request_method string <optional>
"GET" Request method. Supported are "GET" and "POST".
overwrite_header Object <optional>
An object containing fields for overwriting request headers. For example: { "Content-Type": "image/png" }.
post_data * <optional>
The request body that will be sent in a "POST" request.
param * <optional>
An optional parameter that will be passed to the module:assets~AssetCallback.
Source:

AssetType

Asset type. Defines which type of data will be loaded, e.g: json, plain text, binary buffer, ...
Type:
  • number
Source:
See:

PackCallback()

Callback executed after the whole pack of assets is loaded.
Source:

ProgressCallback(rate)

Callback for the progress of loading.
Parameters:
Name Type Description
rate number Amount of loaded data: 0 to 1.
Source: