Parser Class
Module: cc.AssetManager
Parse the downloaded file, it's a singleton, all member can be accessed with cc.assetManager.parser
Index
Methods
registerRegister custom handler if you want to change default behavior or extend parser to parse other format fileparseUse corresponding handler to parse file
Details
Methods
register
Register custom handler if you want to change default behavior or extend parser to parse other format file
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/parser.js:443 |
Parameters
typestring | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}handlerFunction The corresponding handler
Examples
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
Use corresponding handler to parse file
| meta | description |
|---|---|
| Defined in | cocos2d/core/asset-manager/parser.js:474 |
Parameters
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
Examples
downloader.downloadFile('test.jpg', {responseType: 'blob'}, null, (err, file) => {
parser.parse('test.jpg', file, '.jpg', null, (err, img) => console.log(err));
});