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:

  1. Text
  2. Image
  3. Audio
  4. Assets
  5. Scripts

Index

Properties
Methods
  • loadSubpackage cc.loader.downloader.loadSubpackage is deprecated, please use loadBundle instead
  • register Register custom handler if you want to change default behavior or extend downloader to download other format file
  • download 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:212
maxConcurrency

The maximum number of concurrent when downloading

meta description
Type Number
Defined in cocos2d/core/asset-manager/downloader.js:227
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:240
maxRetryCount

The max number of retries when fail

meta description
Type Number
Defined in cocos2d/core/asset-manager/downloader.js:253
retryInterval

Wait for while before another retry, unit: ms

meta description
Type Number
Defined in cocos2d/core/asset-manager/downloader.js:269

Methods

loadSubpackage

cc.loader.downloader.loadSubpackage is deprecated, please use loadBundle instead

meta description
Defined in cocos2d/core/asset-manager/deprecated.js:571
Deprecated cc.loader.downloader.loadSubpackage is deprecated, please use AssetManager.loadBundle instead
Parameters
  • name String Subpackage name
  • completeCallback Function Callback invoked when subpackage loaded
    • error 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:395
Parameters
  • type string | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}
  • handler Function handler
    • url string url
    • options Object some optional paramters will be transferred to handler.
    • onComplete Function callback when finishing downloading
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:426
Parameters
  • url string The url should be downloaded
  • type 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 failed
    • maxConcurrency Number The maximum number of concurrent when downloading
    • maxRequestsPerFrame Number The maximum number of request can be launched per frame when downloading
    • priority Number The priority of this url, default is 0, the greater number is higher priority.
  • onComplete Function callback when finishing downloading
    • err Error The occurred error, null indicetes success
    • contetnt The downloaded file
Examples
download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));

results matching ""

    No results matching ""