partey_workadventure/front/src/Phaser/Components/Loader.ts

28 lines
1.1 KiB
TypeScript
Raw Normal View History

2021-01-30 20:33:31 +01:00
const LogoNameIndex: string = 'logo';
const LogoResource: string = 'resources/logos/logo.png';
export const addLoader = (scene: Phaser.Scene): void => {
const loaderPlugin = scene.load.image(LogoNameIndex, LogoResource);
loaderPlugin.spritesheet(LogoNameIndex, LogoResource);
const promiseLoadLogoTexture = new Promise<Phaser.GameObjects.Image>((res) => {
if (loaderPlugin.textureManager.exists(LogoNameIndex)) {
return res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex));
}
loaderPlugin.once(`filecomplete-spritesheet-${LogoNameIndex}`, () => {
res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex))
});
});
const progress = scene.add.graphics();
scene.load.on('progress', (value: number) => {
progress.clear();
progress.fillStyle(0xffffff, 1);
progress.fillRect(0, 270, 800 * value, 60);
});
scene.load.on('complete', () => {
2021-01-30 20:33:31 +01:00
promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => {
resLoadingImage.destroy();
});
progress.destroy();
});
}