new Tiny.loaders.Loader(baseUrl, concurrency)
| Name | Type | Default | Description |
|---|---|---|---|
baseUrl |
string | '' |
optional
The base url for all resources loaded by this loader. |
concurrency |
number | 10 |
optional
The number of resources to load concurrently. |
extends
- module:resource-loader.resourceloader
methods
-
statictiny.loaders.loader.addtinymiddleware(fn)
-
Adds a default middleware to the Tiny loader.
Name Type Description fnfunction The middleware to add.
-
staticTiny.loaders.Loader.addTinyPreMiddleware(fn)
-
Adds a default middleware pre the Tiny loader.
Name Type Description fnfunction The middleware to add pre.
- Version:
- 1.1.7
-
add(name, url, options, cb) ❯ {Tiny.loaders.Loader}
-
Adds a resource (or multiple resources) to the loader queue.
This function can take a wide variety of different parameters. The only thing that is always
required the url to load. All the following will work:loader // normal param syntax .add('key', 'http://...', function () {}) .add('http://...', function () {}) .add('http://...') // object syntax .add({ name: 'key1' url: 'data:image/png;base64,iV...Jggg==' }, function () {}) .add({ url: 'http://...' }, function () {}) .add({ name: 'key3', url: 'http://...' onComplete: function () {} }) .add({ url: 'https://...', onComplete: function () {}, crossOrigin: true }) // you can pass JSONObject .add({ url: 'key4.json', // the name can be anything, but the extname must be .json metadata: { JSONObject: {"meta":{"image":"https://...","size":{"w":1730,"h":1158},"scale":"1"},"frames":{}}, fallback: function () {} }, xhrType: Tiny.loaders.Resource.XHR_RESPONSE_TYPE.JSONOBJECT, }) // you can also pass an array of objects or urls or both .add([ { name: 'key5', url: 'http://...', onComplete: function () {} }, { url: 'http://...', onComplete: function () {} }, 'http://...', 'data:image/png;base64,iV...Jggg==' ]) // and you can use both params and options .add('key6', 'http://...', { crossOrigin: true }, function () {}) .add('http://...', { crossOrigin: true }, function () {});Name Type Description namestring optional The name of the resource to load, if not passed the url is used.
urlstring optional The url for this resource, relative to the baseUrl of this loader.
optionsobject optional The options for the load.
Name Type Default Description crossOriginboolean optional Is this request cross-origin? Default is to determine automatically.
loadTypeTiny.loaders.Resource.LOAD_TYPE XHR optional How should this resource be loaded?「
XHR, IMAGE, AUDIO, VIDEO」xhrTypeTiny.loaders.Resource.XHR_RESPONSE_TYPE DEFAULT optional How should the data being loaded be interpreted when using XH?「
BLOB, BUFFER, DEFAULT, DOCUMENT, JSON, JSONOBJECT, TEXT」metadataobject optional Extra configuration for middleware and the Resource object.
Name Type Default Description loadElementHTMLImageElement | HTMLAudioElement | HTMLVideoElement null optional The element to use for loading, instead of creating one.
skipSourceboolean false optional Skips adding source(s) to the load element. This is useful if you want to pass in a
loadElementthat you already added load sources to.JSONObjectobject optional 加载的资源如果是一个 JSON 对象,将对象在这里传入,同时传入
url的格式为:*.json,xhrType的格式为:JSONOBJECTfallbackfunction optional Spritesheet 解析识别时的兜底回调
cbfunction optional Function to call when this specific resource completes loading.
- Version:
- 1.1.7
Returns:
Type Description Tiny.loaders.Loader Returns itself. -
run()
-
执行加载
Name Type Description opts.resourcesarray 资源集合
opts.onProgressfunction 加载进度回调函数
opts.onCompletefunction 单个资源加载完成回调函数
opts.onErrorfunction 单个资源加载失败回调函数
opts.onAllCompletefunction 所有资源加载完成回调函数