Pipeline
Class
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.
Index
Methods
constructor
Constructor, pass an array of pipes to construct a new Pipeline,...insertPipe
Insert a new pipe at the given index of the pipeline.insertPipeAfter
Insert a pipe to the end of an existing pipe.appendPipe
Add a new pipe at the end of the pipeline.flowIn
Let new items flow into the pipeline.copyItemStates
Copy the item states from one source item to all destination items.getItem
Returns an item in pipeline.removeItem
Removes an completed item in pipeline.clear
Clear the current pipeline, this function will clean up the items.
Details
Methods
constructor
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.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:112 |
Parameters
pipes
Array
Examples
var pipeline = new Pipeline([
{
id: 'Downloader',
handle: function (item, callback) {},
async: true
},
{id: 'Parser', handle: function (item) {}, async: false}
]);
insertPipe
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.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:156 |
Parameters
insertPipeAfter
Insert a pipe to the end of an existing pipe. The existing pipe must be a valid pipe in the pipeline.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:199 |
Parameters
appendPipe
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.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:216 |
Parameters
pipe
Object The pipe to be appended
flowIn
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.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:240 |
Parameters
items
Array
Examples
pipeline.flowIn([
'res/Background.png',
{
id: 'res/scene.json',
type: 'scene',
name: 'scene',
skips: ['Downloader']
}
]);
copyItemStates
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.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:325 |
Parameters
srcItem
Object The source itemdstItems
Array | Object A single destination item or an array of destination items
getItem
Returns an item in pipeline.
meta | description |
---|---|
Returns | Object |
Defined in | cocos2d/core/load-pipeline/pipeline.js:354 |
Parameters
id
Object The id of the item
removeItem
Removes an completed item in pipeline. It will only remove the cache in the pipeline or loader, its dependencies won't be released. cc.loader provided another method to completely cleanup the resource and its dependencies, please refer to cc.loader.release
meta | description |
---|---|
Returns | Boolean |
Defined in | cocos2d/core/load-pipeline/pipeline.js:374 |
Parameters
id
Object The id of the item
clear
Clear the current pipeline, this function will clean up the items.
meta | description |
---|---|
Defined in | cocos2d/core/load-pipeline/pipeline.js:394 |