Cocos Creator API

1.0.0

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

Pipeline

A pipeline describes a sequence of manipulations, each manipulation is called a pipe. It's designed for loading process, so items should be urls, and the url will be the identity of each item during the process. A list of items can flow in the pipeline and it will output the results of all pipes. They flow in the pipeline like water in tubes, they go through pipe by pipe separately. Finally all items will flow out the pipeline and the process is finished.

Methods

Pipeline
(
  • pipes
)

Constructor, pass an array of pipes to construct a new Pipeline, the pipes will be chained in the given order. A pipe is an object which must contain an id in string and a handle function, the id must be unique in the pipeline. It can also include async property to identify whether it's an asynchronous process.

name type description
pipes Array

examples:

var pipeline = new Pipeline([
     {
         id: 'Downloader',
         handle: function (item, callback) {},
         async: true
     },
     {id: 'Parser', handle: function (item) {}, async: false}
 ]);

insertPipe
(
  • pipe
  • index
)

Insert a new pipe at the given index of the pipeline. A pipe must contain an id in string and a handle function, the id must be unique in the pipeline.

name type description
pipe Object

The pipe to be inserted

index Number

The index to insert

appendPipe
(
  • pipe
)

Add a new pipe at the end of the pipeline. A pipe must contain an id in string and a handle function, the id must be unique in the pipeline.

name type description
pipe Object

The pipe to be appended

flowIn
(
  • urlList
)
Array

Let new items flow into the pipeline. Each item can be a simple url string or an object, if it's an object, it must contain id property. You can specify its type by type property, by default, the type is the extension name in src. By adding a skips property including pipe ids, you can skip these pipe. The object can contain any supplementary property as you want.

name type description
urlList Array

returns:

type: Array

Items accepted by the pipeline

examples:

pipeline.flowIn([
     'res/Background.png',
     {
         id: 'res/scene.json',
         type: 'scene',
         name: 'scene',
         skips: ['Downloader']
     }
 ]);

flowInDeps
(
  • urlList
  • callback
)
Array

Let new items flow into the pipeline and give a callback when the list of items are all completed. This is for loading dependencies for an existing item in flow, usually used in a pipe logic. For example, we have a loader for scene configuration file in JSON, the scene will only be fully loaded after all its dependencies are loaded, then you will need to use function to flow in all dependencies found in the configuration file, and finish the loader pipe only after all dependencies are loaded (in the callback).

name type description
urlList Array
callback Function

returns:

type: Array

Items accepted by the pipeline

copyItemStates
(
  • srcItem
  • dstItems
)

Copy the item states from one source item to all destination items. It's quite useful when a pipe generate new items from one source item, then you should flowIn these generated items into pipeline, but you probably want them to skip all pipes the source item already go through, you can achieve it with this API.

For example, an unzip pipe will generate more items, but you won't want them to pass unzip or download pipe again.

name type description
srcItem Object

The source item

dstItems Array | Object

A single destination item or an array of destination items

isFlowing ( ) Boolean

Returns whether the pipeline is flowing (contains item) currently.

returns:

type: Boolean

getItems ( ) LoadingItems

Returns all items in pipeline.

returns:

type: LoadingItems

getItems ( ) LoadingItems

Returns an item in pipeline.

returns:

type: LoadingItems

removeItem ( ) Boolean

Removes an item in pipeline, no matter it's in progress or completed.

returns:

type: Boolean

succeed or not

clear ( )

Clear the current pipeline, this function will clean up the items.

onProgress
(
  • completedCount
  • totalCount
  • item
)

This is a callback which will be invoked while an item flow out the pipeline, you should overwrite this function.

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:

pipeline.onProgress = function (completedCount, totalCount, item) {
     var progress = (100 * completedCount / totalCount).toFixed(2);
     cc.log(progress + '%');
 }

onComplete
(
  • error
  • items
)

This is a callback which will be invoked while all items flow out the pipeline, you should overwirte this function.

name type description
error Array

All errored urls will be stored in this array, if no error happened, then it will be null

items LoadingItems

All items.

examples:

pipeline.onComplete = function (error, items) {
     if (error)
         cc.log('Completed with ' + error.length + ' errors');
     else
         cc.log('Completed ' + items.totalCount + ' items');
 }

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