Cocos Creator API

1.4.x

Cocos Creator is a highly customizable game development tool that utilizes the power of cocos2d-x.

LoadingItems

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.

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.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

Methods

onProgress
(
  • completedCount
  • totalCount
  • item
)

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.

name type description
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
(
  • errors
  • items
)

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.

name type description
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
(
  • pipeline
  • urlList
  • onProgress
  • onComplete
)
LoadingItems static

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.

name type description
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

returns:

type: LoadingItems

The LoadingItems queue obejct

examples:

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
(
  • item
)
LoadingItems static

Retrieve the LoadingItems queue object for an item.