Downloader
类型
模块: cc.AssetManager
管理所有下载过程,downloader 是个单例,所有成员能通过 cc.assetManager.downloader
访问,它能下载以下几种类型的文件:
- 文本
- 图片
- 音频
- 资源
- 脚本
索引
属性(properties)
remoteServerAddress
String
远程服务器地址maxConcurrency
Number
下载时的最大并发数maxRequestsPerFrame
Number
下载时每帧可以启动的最大请求数maxRetryCount
Number
失败重试次数retryInterval
Number
重试的间隔时间
方法
loadSubpackage
cc.loader.downloader.loadSubpackage
is deprecated, please use loadBundle insteadregister
当你想修改默认行为或者拓展 downloader 来下载其他格式文件时可以注册自定义的 handlerdownload
在限制下使用对应的 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 namecompleteCallback
Function Callback invoked when subpackage loadederror
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
示例
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 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
示例
download('http://example.com/test.tga', '.tga', {onFileProgress: (loaded, total) => console.lgo(loaded/total)}, onComplete: (err) => console.log(err));