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.

name type description
item Object

The item to query

returns:

type: LoadingItems

The LoadingItems queue obejct

itemComplete
(
  • item
)
static

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

name type description
item Object

The item which has completed

append
(
  • urlList
)
Array

Add urls to the LoadingItems queue.

name type description
urlList Array

The url list to be appended, the url can be object or string

returns:

type: Array

The accepted url list, some invalid items could be refused.

allComplete ( )

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

isCompleted ( ) Boolean

Check whether all items are completed.

returns:

type: Boolean

isItemCompleted
(
  • id
)
Boolean

Check whether an item is completed.

name type description
id String

The item's id.

returns:

type: Boolean

exists
(
  • id
)
Boolean

Check whether an item exists.

name type description
id String

The item's id.

returns:

type: Boolean

getContent
(
  • id
)
Object

Returns the content of an internal item.

name type description
id String

The item's id.

returns:

type: Object

getError
(
  • id
)
Object

Returns the error of an internal item.

name type description
id String

The item's id.

returns:

type: Object

addListener
(
  • key
  • callback
  • target
)
Boolean

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

name type description
key String
callback Function

can be null

target Object

can be null

returns:

type: Boolean

whether the key is new

hasListener
(
  • key
  • [callback ]
  • [target ]
)
Boolean

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.

name type description
key String
callback optional Function
target optional Object

returns:

type: Boolean

remove
(
  • key
  • callback
  • target
)
Boolean

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

name type description
key String
callback Function
target Object

returns:

type: Boolean

removed

removeAllListeners
(
  • key
)

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

name type description
key String | Object

The event key to be removed or the target to be removed

itemComplete
(
  • id
)

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

name type description
id String

The item url

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
(
  • key
  • [p1 ]
  • [p2 ]
  • [p3 ]
  • [p4 ]
  • [p5 ]
)

Inherited from CallbacksInvoker:

name type description
key String
p1 optional Any
p2 optional Any
p3 optional Any
p4 optional Any
p5 optional Any

invokeAndRemove
(
  • key
  • [p1 ]
  • [p2 ]
  • [p3 ]
  • [p4 ]
  • [p5 ]
)

Inherited from CallbacksInvoker:

name type description
key String
p1 optional Any
p2 optional Any
p3 optional Any
p4 optional Any
p5 optional Any

bindKey
(
  • key
  • [remove =false]
)
Function

Inherited from CallbacksInvoker:

name type description
key String
remove optional Boolean false

remove callbacks after invoked

returns:

type: Function

the new callback which will invoke all the callbacks binded with the same supplied key

add
(
  • key
  • callback
  • [target ]
)
Boolean

name type description
key String
callback Function
target optional Object

can be null

returns:

type: Boolean

whether the key is new

has
(
  • key
  • [callback ]
  • [target ]
)
Boolean

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.

name type description
key String
callback optional Function
target optional Object

returns:

type: Boolean

removeAll
(
  • key
)

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

name type description
key String | Object

The event key to be removed or the target to be removed

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