Downloader
Class
Module: cc.AssetManager
Control all download process, it is a singleton. All member can be accessed with cc.assetManager.downloader
, it can download several types of files:
- Text
- Image
- Audio
- Assets
- Scripts
Index
Properties
remoteServerAddress
String
The address of remote servermaxConcurrency
Number
The maximum number of concurrent when downloadingmaxRequestsPerFrame
Number
The maximum number of request can be launched per frame when downloadingmaxRetryCount
Number
The max number of retries when failretryInterval
Number
Wait for while before another retry, unit: ms
Methods
loadSubpackage
cc.loader.downloader.loadSubpackage
is deprecated, please use loadBundle insteadregister
Register custom handler if you want to change default behavior or extend downloader to download other format filedownload
Use corresponding handler to download file under limitation
Details
Properties
remoteServerAddress
The address of remote server
meta | description |
---|---|
Type | String |
Defined in | cocos2d/core/asset-manager/downloader.js:214 |
maxConcurrency
The maximum number of concurrent when downloading
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/asset-manager/downloader.js:229 |
maxRequestsPerFrame
The maximum number of request can be launched per frame when downloading
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/asset-manager/downloader.js:242 |
maxRetryCount
The max number of retries when fail
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/asset-manager/downloader.js:255 |
retryInterval
Wait for while before another retry, unit: ms
meta | description |
---|---|
Type | Number |
Defined in | cocos2d/core/asset-manager/downloader.js:271 |
Methods
loadSubpackage
cc.loader.downloader.loadSubpackage
is deprecated, please use loadBundle instead
meta | description |
---|---|
Defined in | cocos2d/core/asset-manager/deprecated.js:585 |
Deprecated | cc.loader.downloader.loadSubpackage is deprecated, please use AssetManager.loadBundle instead |
Parameters
name
String Subpackage namecompleteCallback
Function Callback invoked when subpackage loadederror
Error error information
register
Register custom handler if you want to change default behavior or extend downloader to download other format file
meta | description |
---|---|
Defined in | cocos2d/core/asset-manager/downloader.js:397 |
Parameters
type
string | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}handler
Function handler
Examples
downloader.register('.tga', (url, options, onComplete) => onComplete(null, null));
downloader.register({'.tga': (url, options, onComplete) => onComplete(null, null), '.ext': (url, options, onComplete) => onComplete(null, null)});
download
Use corresponding handler to download file under limitation
meta | description |
---|---|
Defined in | cocos2d/core/asset-manager/downloader.js:428 |
Parameters
url
string The url should be downloadedtype
string The type indicates that which handler should be used to download, such as '.jpg'options
Object some optional paramters will be transferred to the corresponding handler.onFileProgress
Function progressive callback will be transferred to handler.maxRetryCount
Number How many times should retry when download failedmaxConcurrency
Number The maximum number of concurrent when downloadingmaxRequestsPerFrame
Number The maximum number of request can be launched per frame when downloadingpriority
Number The priority of this url, default is 0, the greater number is higher priority.
onComplete
Function callback when finishing downloadingerr
Error The occurred error, null indicetes successcontetnt
The downloaded file
Examples
download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));