Core. LoaderManager

LoaderManager Class is used to load resources in batches. This class is a singleton. Do not manually instantiate this class. Please visit via Laya.loader.

When all the queue loads are completed, the Event.COMPLETE event is distributed. If any of the queues fails, the Event.ERROR event is issued, and the event callback parameter is the address of the loaded error resource.

LoaderManager Class provides the following functions: < Multi threading: the default 5 load thread, you can modify the number of threads through the maxLoader property;
Multiple priority: there are 0-4 priority in 5, priority priority load. 0 highest and 4 lowest;
Repeat filtering: automatically filtering, repeated loading (not loading multiple simultaneous addresses at the same time), and reusing cache resources to prevent repeated loading;
*

Constructor

new LoaderManager()

Create a new one LoaderManager Example。

Be careful: Please use Laya.loader to load resources. This is a singleton. Do not instantiate this class manually, otherwise it will lead to unpredictable problems.

See:
  • net.Loader

Extends

Member

maxLoader :int

The maximum download thread defaults to 5
Default Value:
  • 5

retryDelay :int

How long does the delay last? Retry the error. Try again immediately by default
Default Value:
  • 0

retryNum :int

The number of times after the error has been loaded. Try again by default
Default Value:
  • 1

Methods

cacheRes(url, data)

Cache resources.
Parameters:
Name Type Description
url String Resource address.
data Object What you want to cache.

cancelLoadByUrl(url)

Clear the unloaded content from the address
Parameters:
Name Type Description
url String Resource address

cancelLoadByUrls(urls)

Clear the unloaded content according to the address collection
Parameters:
Name Type Description
urls Array Resource address set

clearRes(url, forceDispose)

Clear the specified resource address cache.
Parameters:
Name Type Description
url String Resource address.
forceDispose Boolean If destruction is mandatory, some resources are destroyed by reference counting. If forceDispose=true, the reference count is ignored and destroyed directly, such as Texture, and defaults to false

clearResByGroup(group)

Clear resources according to groups.
Parameters:
Name Type Description
group String Grouping name

clearUnLoaded()

Clean up the current incomplete load, and all loaded contents are stopped loading.

create(url, completeopt, progressopt, clasopt, paramsopt, priorityopt) → {Object}

According to the object to create an uninitialized resource type clas, followed by asynchronous loading resources after loading, initialization of objects resources, and through this object dispatches the Event.LOADED event, event callback parameter values for the object itself. Nested child resources retain the part of the resource path "after".

If the URL is an array, returns true; otherwise, the specified resource class object is returned, and the resource is evaluated by listening to the Event.LOADED event of the object.

Be careful: The cache parameter can only cache control of the resource whose file suffix is atlas, and other resources ignore the cache and force it to reload.

Parameters:
Name Type Attributes Default Description
url Object Resource address or array. If both URL and clas specify the resource type at the same time, the resource type specified by URL is used preferentially. Parameter shape: [{url:xx,clas:xx,priority:xx,params:xx},{url:xx,clas:xx,priority:xx,params:xx}] .
complete Handler <optional>
null progress The resource load progress callback, the callback parameter value, is the progress information loaded by the current resource (0-1).
progress Handler <optional>
null clas Resource class name. If both URL and clas specify the resource type at the same time, the resource type specified by URL is used preferentially. Parameter shape such as: Texture.
clas Class <optional>
null type Resource type. Parameter shape such as: Loader.IMAGE.
params Array <optional>
null priority (default = 1) loaded priority, priority high priority loading. There are 0-4 total 5 priority, 0 highest and 4 lowest.
priority int <optional>
1 cache Do you cache the loaded resources?.
Returns:
Type:
Object
If URL is an array, returns true; otherwise, the specified resource class object is returned.

decodeBitmaps(urls)

Decode Texture or atlas
Parameters:
Name Type Description
urls Array Texture address or atlas address set

event(type, dataopt) → {Boolean}

Dispatch events.
Inherited From:
Parameters:
Name Type Attributes Default Description
type String Event type.
data Object <optional>
null data (optional) callback data. Be careful: If you need to pass multiple parameters, P1, P2, P3, you can use the array structure, such as: [p1,p2,p3,...] If you need to call a single parameter P, and P is an array, you need to use a structure such as: [p] Other single parameters, P, can be passed directly to the parameter P.
Returns:
Type:
Boolean
Is there a listener for this event type? If there is a listener, the value is true, otherwise the value is false.

getRes(url) → {Object}

Gets the resource of the specified resource address.
Parameters:
Name Type Description
url String Resource address.
Returns:
Type:
Object
Return resources.

hasListener(type) → {Boolean}

inspect EventDispatcher Object registers any listeners for a particular event type.
Inherited From:
Parameters:
Name Type Description
type String Event type.
Returns:
Type:
Boolean
If the specified type of listener has been registered, the value is true; otherwise, the value is false.

isMouseEvent(type) → {Boolean}

Detects whether the specified event type is a mouse event.
Inherited From:
Parameters:
Name Type Description
type String Event type.
Returns:
Type:
Boolean
If it is a mouse event, the value is true; otherwise, the value is false.

load(url, completeopt, progressopt, typeopt, priorityopt, cache, groupopt, ignoreCache, useWorkerLoader(default) → {LoaderManager}

Load resources. When the resource loads an error, the object dispatches the Event.ERROR event, which is the value of the resource address that has been loaded.

Because the return value is LoaderManager Object itself, so you can use the following syntax: loaderManager.load (...).Load (...);

Parameters:
Name Type Attributes Default Description
url Object A single resource, address, or resource information array to load. For example: simple array: ["a.png","b.png"] Complex array [{url:"a.png",type:Loader.IMAGE,size:100,priority:1},{url:"b.json",type:Loader.JSON,size:50,priority:1}] .
complete Handler <optional>
null complete Load end callback. According to URL of different types are divided into 2 types: 1. URL type String, is a single source address, if the loading is successful, the callback parameter values for the completion of the loading of resources, otherwise null; 2. URL is an array type, a group to load the resource specified, if all loaded successfully, then the callback parameter value true, or false.
progress Handler <optional>
null progress Load progress callback. The callback parameter value is the loading progress information for the current resource (0-1).
type String <optional>
null type Resource type. For example: Loader.IMAGE.
priority int <optional>
1 priority (default = 1) loaded priority, priority high priority loading. There are 0-4 total 5 priority, 0 highest and 4 lowest.
cache Boolean Do you cache the load results?.
group String <optional>
null group Grouping makes it easy to manage resources.
ignoreCache Boolean Do you want to ignore the cache and force it to reload?.
useWorkerLoader(default Boolean = false) do you use worker to load (for IMAGE types and ATLAS types only and browser support)?
Returns:
Type:
LoaderManager
this LoaderManager Object itself.

off(type, caller, listener, onceOnly) → {EventDispatcher}

from EventDispatcher Delete listeners in object.
Inherited From:
Parameters:
Name Type Description
type String Event type.
caller Object The domain of the event listener function.
listener function Event listener function.
onceOnly Boolean (optional) if the value is true, only the listeners added by the once method are removed.
Returns:
Type:
EventDispatcher
this EventDispatcher Object.

offAll(typeopt) → {EventDispatcher}

from EventDispatcher Removes all listeners that specify the type of event in the object.
Inherited From:
Parameters:
Name Type Attributes Default Description
type String <optional>
null type (optional) event type. If the value is null, all types of listeners for this object are removed.
Returns:
Type:
EventDispatcher
this EventDispatcher Object.

on(type, caller, listener, argsopt) → {EventDispatcher}

Use EventDispatcher Object registers the event listener object of the specified type so that listeners can receive event notifications.
Inherited From:
Parameters:
Name Type Attributes Default Description
type String Event type.
caller Object The domain of the event listener function.
listener function Event listener function.
args Array <optional>
null args Optional callback parameters for the event listener function.
Returns:
Type:
EventDispatcher
this EventDispatcher Object.

once(type, caller, listener, argsopt) → {EventDispatcher}

Use EventDispatcher Object registers the event listener object of the specified type so that the listener can receive the event notification, which is automatically removed after a response event.
Inherited From:
Parameters:
Name Type Attributes Default Description
type String Event type.
caller Object The domain of the event listener function.
listener function Event listener function.
args Array <optional>
null args Optional callback parameters for the event listener function.
Returns:
Type:
EventDispatcher
this EventDispatcher Object.

setGroup(url, group)

Set resource groups.
Parameters:
Name Type Description
url String Resource address.
group String Grouping name

Event

complete

See:
  • events.Event

error

See:
  • events.Event