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
  • maxConcurrency Number The maximum number of concurrent when downloading
  • maxRequestsPerFrame Number The maximum number of request can be launched per frame when downloading
  • maxRetryCount Number The max number of retries when fail
  • retryInterval Number Wait for while before another retry, unit: ms
Methods

Details

Properties

maxConcurrency

The maximum number of concurrent when downloading

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

The max number of retries when fail

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

Wait for while before another retry, unit: ms

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

Methods

loadSubpackage

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

meta description
Defined in cocos2d/core/asset-manager/deprecated.js:574
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
downloadDomImage

Use Image element to download image

meta description
Returns HTMLImageElement
Defined in cocos2d/core/asset-manager/downloader.js:266
Parameters
  • url string Url of the image
  • options Object Some optional paramters
  • onComplete Function Callback when image loaded or failed
    • err Error The occurred error, null indicetes success
    • img HTMLImageElement The loaded Image element, null if error occurred
Examples
downloadDomImage('http://example.com/test.jpg', null, (err, img) => console.log(err));
downloadDomAudio

Use audio element to download audio

meta description
Returns HTMLAudioElement
Defined in cocos2d/core/asset-manager/downloader.js:290
Parameters
  • url string Url of the audio
  • options Object Some optional paramters
  • onComplete Function Callback invoked when audio loaded or failed
    • err Error The occurred error, null indicetes success
    • audio HTMLAudioElement The loaded audio element, null if error occurred
Examples
downloadDomAudio('http://example.com/test.mp3', null, (err, audio) => console.log(err));
downloadFile

Use XMLHttpRequest to download file

meta description
Returns XMLHttpRequest
Defined in cocos2d/core/asset-manager/downloader.js:314
Parameters
  • url string Url of the file
  • options Object Some optional paramters
    • responseType string Indicate which type of content should be returned
    • withCredentials boolean Indicate whether or not cross-site Access-Contorl requests should be made using credentials
    • mimeType string Indicate which type of content should be returned. In some browsers, responseType does't work, you can use mimeType instead
    • timeout Number Represent the number of ms a request can take before being terminated.
    • header Object The header should be tranferred to server
  • onFileProgress Function Callback continuously during download is processing
    • loaded Number Size of downloaded content.
    • total Number Total size of content.
  • onComplete Function Callback when file loaded or failed
    • err Error The occurred error, null indicetes success
    • response The loaded content, null if error occurred, type of content can be indicated by options.responseType
Examples
downloadFile('http://example.com/test.bin', {responseType: 'arraybuffer'}, null, (err, arrayBuffer) => console.log(err));
downloadScript

Load script

meta description
Defined in cocos2d/core/asset-manager/downloader.js:348
Parameters
  • url string Url of the script
  • options Object Some optional paramters
    • isAsync boolean Indicate whether or not loading process should be async
  • onComplete Function Callback when script loaded or failed
    • err Error The occurred error, null indicetes success
Examples
downloadScript('http://localhost:8080/index.js', null, (err) => console.log(err));
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:377
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:408
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 ""