Parser Class

Module: cc.AssetManager

Parse the downloaded file, it's a singleton, all member can be accessed with cc.assetManager.parser

Index

Methods

Details

Methods

parseImage

Parse image file

meta description
Defined in cocos2d/core/asset-manager/parser.js:53
Parameters
  • file Blob The downloaded file
  • options Object Some optional paramters
  • onComplete Function callback when finish parsing.
    • err Error The occurred error, null indicetes success
    • img ImageBitmap | HTMLImageElement The parsed content
Examples
downloader.downloadFile('test.jpg', {responseType: 'blob'}, null, (err, file) => {
     parser.parseImage(file, null, (err, img) => console.log(err));
});
parseAudio

Parse audio file

meta description
Defined in cocos2d/core/asset-manager/parser.js:93
Parameters
  • file ArrayBuffer | HTMLAudioElement The downloaded file
  • options Object Some optional paramters
  • onComplete Function Callback when finish parsing.
    • err Error The occurred error, null indicetes success
    • audio AudioBuffer | HTMLAudioElement The parsed content
Examples
downloader.downloadFile('test.mp3', {responseType: 'arraybuffer'}, null, (err, file) => {
     parser.parseAudio(file, null, (err, audio) => console.log(err));
});
parsePVRTex

Parse pvr file

meta description
Defined in cocos2d/core/asset-manager/parser.js:128
Parameters
  • file ArrayBuffer | ArrayBufferView The downloaded file
  • options Object Some optional paramters
  • onComplete Function Callback when finish parsing.
    • err Error The occurred error, null indicetes success
    • pvrAsset Object The parsed content
Examples
downloader.downloadFile('test.pvr', {responseType: 'arraybuffer'}, null, (err, file) => {
     parser.parsePVRTex(file, null, (err, pvrAsset) => console.log(err));
});
parsePKMTex

Parse pkm file

meta description
Defined in cocos2d/core/asset-manager/parser.js:199
Parameters
  • file ArrayBuffer | ArrayBufferView The downloaded file
  • options Object Some optional paramters
  • onComplete Function Callback when finish parsing.
    • err Error The occurred error, null indicetes success
    • etcAsset Object The parsed content
Examples
downloader.downloadFile('test.pkm', {responseType: 'arraybuffer'}, null, (err, file) => {
     parser.parsePKMTex(file, null, (err, etcAsset) => console.log(err));
});
parsePlist

Parse plist file

meta description
Defined in cocos2d/core/asset-manager/parser.js:269
Parameters
  • file string The downloaded file
  • options Object Some optional paramters
  • onComplete Function Callback when finish parsing
    • err Error The occurred error, null indicetes success
    • data The parsed content
Examples
downloader.downloadFile('test.plist', {responseType: 'text'}, null, (err, file) => {
     parser.parsePlist(file, null, (err, data) => console.log(err));
});
parseImport

Deserialize asset file

meta description
Defined in cocos2d/core/asset-manager/parser.js:298
Parameters
  • file Object The serialized json
  • options Object Some optional paramters
  • onComplete Function Callback when finish parsing
    • err Error The occurred error, null indicetes success
    • asset Asset The parsed content
Examples
downloader.downloadFile('test.json', {responseType: 'json'}, null, (err, file) => {
     parser.parseImport(file, null, (err, data) => console.log(err));
});
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:336
Parameters
  • type string | Object Extension likes '.jpg' or map likes {'.jpg': jpgHandler, '.png': pngHandler}
  • handler Function The corresponding handler
    • file File
    • options Object Some optional paramter
    • onComplete Function callback when finishing parsing
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:367
Parameters
  • id string The id of file
  • file Any File
  • type string The corresponding type of file, likes '.jpg'.
  • options Object Some optional paramters will be transferred to the corresponding handler.
  • onComplete Function callback when finishing downloading
    • err Error The occurred error, null indicetes success
    • contetnt The parsed file
Examples
downloader.downloadFile('test.jpg', {responseType: 'blob'}, null, (err, file) => {
     parser.parse('test.jpg', file, '.jpg', null, (err, img) => console.log(err));
});

results matching ""

    No results matching ""