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
remoteServerAddressStringThe address of remote servermaxConcurrencyNumberThe maximum number of concurrent when downloadingmaxRequestsPerFrameNumberThe maximum number of request can be launched per frame when downloadingmaxRetryCountNumberThe max number of retries when failretryIntervalNumberWait for while before another retry, unit: ms
Methods
loadSubpackagecc.loader.downloader.loadSubpackageis deprecated, please use loadBundle insteadregisterRegister custom handler if you want to change default behavior or extend downloader to download other format filedownloadUse 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
nameString Subpackage namecompleteCallbackFunction Callback invoked when subpackage loadederrorError 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
typestring | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}handlerFunction 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
urlstring The url should be downloadedtypestring The type indicates that which handler should be used to download, such as '.jpg'optionsObject some optional paramters will be transferred to the corresponding handler.onFileProgressFunction progressive callback will be transferred to handler.maxRetryCountNumber How many times should retry when download failedmaxConcurrencyNumber The maximum number of concurrent when downloadingmaxRequestsPerFrameNumber The maximum number of request can be launched per frame when downloadingpriorityNumber The priority of this url, default is 0, the greater number is higher priority.
onCompleteFunction callback when finishing downloadingerrError The occurred error, null indicetes successcontetntThe downloaded file
Examples
download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));