Parser 类型
模块: cc.AssetManager
解析已下载的文件,parser 是一个单例, 所有成员能通过 cc.assetManaager.parser 访问
索引
方法
Details
方法
register
当你想修改默认行为或者拓展 parser 来解析其他格式文件时可以注册自定义的handler
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/parser.js:443 |
参数列表
typestring | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}handlerFunction The corresponding handler
示例
parser.register('.tga', (file, options, onComplete) => onComplete(null, null));
parser.register({'.tga': (file, options, onComplete) => onComplete(null, null), '.ext': (file, options, onComplete) => onComplete(null, null)});
parse
使用对应的handler来解析文件
| meta | description |
|---|---|
| 定义于 | cocos2d/core/asset-manager/parser.js:474 |
参数列表
idstring The id of filefileAny Filetypestring The corresponding type of file, likes '.jpg'.optionsObject Some optional paramters will be transferred to the corresponding handler.onCompleteFunction callback when finishing downloadingerrError The occurred error, null indicetes successcontetntThe parsed file
示例
downloader.downloadFile('test.jpg', {responseType: 'blob'}, null, (err, file) => {
parser.parse('test.jpg', file, '.jpg', null, (err, img) => console.log(err));
});