Cocos Creator API

1.4.x

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

Pipeline

Module: cc

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
(
  • items
)

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 url.
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
items Array

examples:

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

flowInDeps
(
  • urlList
  • callback
)
Array deprecated

deprecated: since v1.3

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 deprecated