This is my first game I made in phaser, and I would like some feed back. I really need help with lowering the load time, because it is way too long. Thanks!
The link: https://relaxed-elion-f7884e.netlify.app/
Loading over 6MB (startSound.mp3) in preload is not a good idea. It’s going to wait for filecomplete…
I’m not sure about the Phaser audio loader, but if you just use HTMLAudioElement directly, you can play as soon as there is enough data available (canplay, canplaythrough events).
Thanks!
If you’re playing music only, you can disable Web Audio. Phaser uses canplaythrough for HTML Audio.
Hi @23Aferg8,
You can try to load the assets of next level in background while playing previus level. Something like this:
class Level1 extends Phaser.Scene {
constructor(){
super('level1');
}
preload(){
this.nextIsLoaded = false;
this.load.image(/*...*/);
this.load.audio(/*...*/);
/* More loads */
this.load.on('complete', () => {
this.scene.launch('loadLevel2');
});
}
/* More code for level1 */
}
class LoadLevel2 extends Phaser.Scene {
constructor(){
super('loadLevel2');
}
preload(){
this.load.image(/*...*/);
this.load.audio(/*...*/);
/* More loads */
this.load.on('complete', () => {
this.scene.get('level1').nextIsloaded = true;
this.scene.stop();
});
}
}
P.S.: not tested.
Regards.
Thanks @jjcapellan, @Milton and @samme!
Key @samme, how would I go about that?
See game config in examples/v3/view/audio/html5-audio/play-audio-file.
You can turn on Compress Images in Netlify Asset optimization settings, that may make a small difference.