Downloader 类型

模块: cc.AssetManager

管理所有下载过程,downloader 是个单例,所有成员能通过 cc.assetManager.downloader 访问,它能下载以下几种类型的文件:

  1. 文本
  2. 图片
  3. 音频
  4. 资源
  5. 脚本

索引

属性(properties)
方法
  • loadSubpackage cc.loader.downloader.loadSubpackage is deprecated, please use loadBundle instead
  • register 当你想修改默认行为或者拓展 downloader 来下载其他格式文件时可以注册自定义的 handler
  • download 在限制下使用对应的 handler 来下载文件

Details

属性(properties)

remoteServerAddress

远程服务器地址

meta description
类型 String
定义于 cocos2d/core/asset-manager/downloader.js:214
maxConcurrency

下载时的最大并发数

meta description
类型 Number
定义于 cocos2d/core/asset-manager/downloader.js:229
maxRequestsPerFrame

下载时每帧可以启动的最大请求数

meta description
类型 Number
定义于 cocos2d/core/asset-manager/downloader.js:242
maxRetryCount

失败重试次数

meta description
类型 Number
定义于 cocos2d/core/asset-manager/downloader.js:255
retryInterval

重试的间隔时间

meta description
类型 Number
定义于 cocos2d/core/asset-manager/downloader.js:271

方法

loadSubpackage

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

meta description
定义于 cocos2d/core/asset-manager/deprecated.js:585
废弃(Deprecated) cc.loader.downloader.loadSubpackage is deprecated, please use AssetManager.loadBundle instead
参数列表
  • name String Subpackage name
  • completeCallback Function Callback invoked when subpackage loaded
    • error Error error information
register

当你想修改默认行为或者拓展 downloader 来下载其他格式文件时可以注册自定义的 handler

meta description
定义于 cocos2d/core/asset-manager/downloader.js:397
参数列表
  • 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
示例
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

在限制下使用对应的 handler 来下载文件

meta description
定义于 cocos2d/core/asset-manager/downloader.js:428
参数列表
  • 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
示例
download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));

条与 "" 相匹配的结果

    没有与 "" 匹配的结果