Fix loading logo of WorkAdventure
This commit is contained in:
parent
f99db4856f
commit
788e22e8b0
@ -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 LogoResource: string = 'resources/logos/logo.png';
|
||||||
|
const LogoFrame: ImageFrameConfig = {frameWidth: 307, frameHeight: 59};
|
||||||
|
|
||||||
export const addLoader = (scene: Phaser.Scene): void => {
|
export const addLoader = (scene: Phaser.Scene): void => {
|
||||||
const loaderPlugin = scene.load.image(LogoNameIndex, LogoResource);
|
let loadingText: Phaser.GameObjects.Text|null = null;
|
||||||
loaderPlugin.spritesheet(LogoNameIndex, LogoResource);
|
|
||||||
const promiseLoadLogoTexture = new Promise<Phaser.GameObjects.Image>((res) => {
|
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));
|
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}`, () => {
|
scene.load.spritesheet(LogoNameIndex, LogoResource, LogoFrame);
|
||||||
res(scene.add.image(scene.game.renderer.width / 2, 100, LogoNameIndex))
|
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);
|
progress.fillRect(0, 270, 800 * value, 60);
|
||||||
});
|
});
|
||||||
scene.load.on('complete', () => {
|
scene.load.on('complete', () => {
|
||||||
|
if(loadingText){
|
||||||
|
loadingText.destroy();
|
||||||
|
}
|
||||||
promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => {
|
promiseLoadLogoTexture.then((resLoadingImage: Phaser.GameObjects.Image) => {
|
||||||
resLoadingImage.destroy();
|
resLoadingImage.destroy();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user