Fix loading logo of WorkAdventure

This commit is contained in:
Gregoire Parant 2021-02-01 16:52:28 +01:00
parent f99db4856f
commit 788e22e8b0
1 changed files with 20 additions and 6 deletions

View File

@ -1,15 +1,26 @@
const LogoNameIndex: string = 'logo';
import ImageFrameConfig = Phaser.Types.Loader.FileTypes.ImageFrameConfig;
const LogoNameIndex: string = 'logoLoading';
const TextName: string = 'Loading...';
const LogoResource: string = 'resources/logos/logo.png';
const LogoFrame: ImageFrameConfig = {frameWidth: 307, frameHeight: 59};
export const addLoader = (scene: Phaser.Scene): void => {
const loaderPlugin = scene.load.image(LogoNameIndex, LogoResource);
loaderPlugin.spritesheet(LogoNameIndex, LogoResource);
let loadingText: Phaser.GameObjects.Text|null = null;
const promiseLoadLogoTexture = new Promise<Phaser.GameObjects.Image>((res) => {
if (loaderPlugin.textureManager.exists(LogoNameIndex)) {
if(scene.load.textureManager.exists(LogoNameIndex)){
return res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex));
}else{
//add loading if logo image is not ready
loadingText = scene.add.text(scene.game.renderer.width / 2, 200, TextName);
}
loaderPlugin.once(`filecomplete-spritesheet-${LogoNameIndex}`, () => {
res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex))
scene.load.spritesheet(LogoNameIndex, LogoResource, LogoFrame);
scene.load.once(`filecomplete-spritesheet-${LogoNameIndex}`, () => {
if(loadingText){
loadingText.destroy();
}
return res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex));
});
});
@ -20,6 +31,9 @@ export const addLoader = (scene: Phaser.Scene): void => {
progress.fillRect(0, 270, 800 * value, 60);
});
scene.load.on('complete', () => {
if(loadingText){
loadingText.destroy();
}
promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => {
resLoadingImage.destroy();
});