LoadingItems Class

Extends CallbacksInvoker

Module: cc

LoadingItems is the queue of items which can flow them into the loading pipeline.
Please don't construct it directly, use LoadingItems.create instead, because we use an internal pool to recycle the queues.
It hold a map of items, each entry in the map is a url to object key value pair.
Each item always contains the following property:

  • id: The identification of the item, usually it's identical to url
  • url: The url
  • type: The type, it's the extension name of the url by default, could be specified manually too.
  • error: The error happened in pipeline will be stored in this property.
  • content: The content processed by the pipeline, the final result will also be stored in this property.
  • complete: The flag indicate whether the item is completed by the pipeline.
  • states: An object stores the states of each pipe the item go through, the state can be: Pipeline.ItemState.WORKING | Pipeline.ItemState.ERROR | Pipeline.ItemState.COMPLETE

    Item can hold other custom properties.
    Each LoadingItems object will be destroyed for recycle after onComplete callback
    So please don't hold its reference for later usage, you can copy properties in it though.

Index

Properties
  • map Object The map of all items.
  • completed Object The map of completed items.
  • totalCount Number Total count of all items.
  • completedCount Number Total count of completed items.
  • active Boolean Activated or not.
Methods
  • onProgress This is a callback which will be invoked while an item flow out the pipeline.
  • onComplete This is a callback which will be invoked while all items is completed,...
  • create The constructor function of LoadingItems, this will use recycled LoadingItems in the internal pool if possible.
  • getQueue Retrieve the LoadingItems queue object for an item.
  • itemComplete Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.
  • append Add urls to the LoadingItems queue.
  • allComplete Complete a LoadingItems queue, please do not call this method unless you know what's happening.
  • isCompleted Check whether all items are completed.
  • isItemCompleted Check whether an item is completed.
  • exists Check whether an item exists.
  • getContent Returns the content of an internal item.
  • getError Returns the error of an internal item.
  • addListener Add a listener for an item, the callback will be invoked when the item is completed.
  • hasListener Check if the specified key has any registered callback.
  • remove Removes a listener.
  • removeAllListeners Removes all callbacks registered in a certain event
  • itemComplete Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.
  • destroy Destroy the LoadingItems queue, the queue object won't be garbage collected, it will be recycled, so every after destroy is not reliable.
  • invoke
  • add
  • hasEventListener Check if the specified key has any registered callback.
  • removeAll Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

Details

Properties

map

The map of all items.

meta description
Type Object
Defined in cocos2d/core/load-pipeline/loading-items.js:212
completed

The map of completed items.

meta description
Type Object
Defined in cocos2d/core/load-pipeline/loading-items.js:220
totalCount

Total count of all items.

meta description
Type Number
Defined in cocos2d/core/load-pipeline/loading-items.js:228
completedCount

Total count of completed items.

meta description
Type Number
Defined in cocos2d/core/load-pipeline/loading-items.js:236
active

Activated or not.

meta description
Type Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:244

Methods

onProgress

This is a callback which will be invoked while an item flow out the pipeline. You can pass the callback function in LoadingItems.create or set it later.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:179
Parameters
  • completedCount Number The number of the items that are already completed.
  • totalCount Number The total number of the items.
  • item Object The latest item which flow out the pipeline.
Examples
loadingItems.onProgress = function (completedCount, totalCount, item) {
     var progress = (100 * completedCount / totalCount).toFixed(2);
     cc.log(progress + '%');
 }
onComplete

This is a callback which will be invoked while all items is completed, You can pass the callback function in LoadingItems.create or set it later.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:195
Parameters
  • errors Array All errored urls will be stored in this array, if no error happened, then it will be null
  • items LoadingItems All items.
Examples
loadingItems.onComplete = function (errors, items) {
     if (error)
         cc.log('Completed with ' + errors.length + ' errors');
     else
         cc.log('Completed ' + items.totalCount + ' items');
 }
create

The constructor function of LoadingItems, this will use recycled LoadingItems in the internal pool if possible. You can pass onProgress and onComplete callbacks to visualize the loading process.

meta description
Returns LoadingItems
Defined in cocos2d/core/load-pipeline/loading-items.js:292
Parameters
  • pipeline Pipeline The pipeline to process the queue.
  • urlList Array The items array.
  • onProgress Function The progression callback, refer to LoadingItems.onProgress
  • onComplete Function The completion callback, refer to LoadingItems.onComplete
Examples
cc.LoadingItems.create(cc.loader, ['a.png', 'b.plist'], function (completedCount, totalCount, item) {
     var progress = (100 * completedCount / totalCount).toFixed(2);
     cc.log(progress + '%');
 }, function (errors, items) {
     if (errors) {
         for (var i = 0; i < errors.length; ++i) {
             cc.log('Error url: ' + errors[i] + ', error: ' + items.getError(errors[i]));
         }
     }
     else {
         var result_a = items.getContent('a.png');
         // ...
     }
 })
getQueue

Retrieve the LoadingItems queue object for an item.

meta description
Returns LoadingItems
Defined in cocos2d/core/load-pipeline/loading-items.js:359
Parameters
  • item Object The item to query
itemComplete

Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:371
Parameters
  • item Object The item which has completed
append

Add urls to the LoadingItems queue.

meta description
Returns Array
Defined in cocos2d/core/load-pipeline/loading-items.js:439
Parameters
  • urlList Array The url list to be appended, the url can be object or string
allComplete

Complete a LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:523
isCompleted

Check whether all items are completed.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:536
isItemCompleted

Check whether an item is completed.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:546
Parameters
exists

Check whether an item exists.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:557
Parameters
getContent

Returns the content of an internal item.

meta description
Returns Object
Defined in cocos2d/core/load-pipeline/loading-items.js:568
Parameters
getError

Returns the error of an internal item.

meta description
Returns Object
Defined in cocos2d/core/load-pipeline/loading-items.js:590
Parameters
addListener

Add a listener for an item, the callback will be invoked when the item is completed.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:611
Parameters
hasListener

Check if the specified key has any registered callback. If a callback is also specified, it will only return true if the callback is registered.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:622
Parameters
remove

Removes a listener. It will only remove when key, callback, target all match correctly.

meta description
Returns Boolean
Defined in cocos2d/core/load-pipeline/loading-items.js:637
Parameters
removeAllListeners

Removes all callbacks registered in a certain event type or all callbacks registered with a certain target.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:652
Parameters
  • key String | Object The event key to be removed or the target to be removed
itemComplete

Complete an item in the LoadingItems queue, please do not call this method unless you know what's happening.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:684
Parameters
destroy

Destroy the LoadingItems queue, the queue object won't be garbage collected, it will be recycled, so every after destroy is not reliable.

meta description
Defined in cocos2d/core/load-pipeline/loading-items.js:728
invoke
meta description
Defined in cocos2d/core/platform/callbacks-invoker.js:236
Parameters
  • key String
  • p1 Any
  • p2 Any
  • p3 Any
  • p4 Any
  • p5 Any
add
meta description
Defined in cocos2d/core/platform/callbacks-invoker.js:97
Parameters
hasEventListener

Check if the specified key has any registered callback. If a callback is also specified, it will only return true if the callback is registered.

meta description
Returns Boolean
Defined in cocos2d/core/platform/callbacks-invoker.js:112
Parameters
removeAll

Removes all callbacks registered in a certain event type or all callbacks registered with a certain target

meta description
Defined in cocos2d/core/platform/callbacks-invoker.js:154
Parameters
  • keyOrTarget String | Object The event key to be removed or the target to be removed

results matching ""

    No results matching ""