-
Notifications
You must be signed in to change notification settings - Fork 0
Loader
Harsh Singh edited this page Jul 22, 2022
·
7 revisions
This module provides 3 functions loadImage
, loadSound
and loadJSON
which can be used for loading images, sounds and json files asynchronously. They return a Promise which is resolved once the asset has been loaded, else rejects.
A Basic, Reusable Asset Loader
const loader = new Bottlecap.Loader();
loader.on('load', onComplete);
loader.on('error', onError);
loader
.addImage('spritesheet', './res/spritesheet.png')
.addSound('bgm', './res/bgm.mp3')
.addJSON('data', './res/data.json')
.load(, onError);
const onLoad = loadedAssets => {
// pass loaded assets to asset manager
};
const onError = e => {
// handle error
};
// render function
render() {
if(loader.loading) {
drawLoadingScreen();
return;
}
// do stuff
}