Loading necessary assets for each scene

Hi,
I don’t want to load all the graphic assets from the beginning. instead of that, load the necessary assets before every stage. for example when playing stage 1, load the resources for stage 2 in the background.

Is that possible in phaser3?.

can anyone help me to solve this?

1 Like

There’s a preload method to every scene, so you can load all of the assets there and create them in the create method.

ex:

function preload ()
{
    this.load.image('einstein', 'assets/pics/ra-einstein.png');
}

function create ()
{
    this.add.image(400, 300, 'einstein');
}

Thanks jake,
But when we load assets of current scene it hold on black screen initially and then load images in create function.I want to load assets of next state in a background of current state.

Gotcha, that’s doable.

Let’s assume you have Scene A, which will have to act as your initial preloader and will contain very minimal assets to ensure a quick loading time. Once loaded, in the create method of Scene A, you can load all of the assets for Scene B like so:

this.load.image('sceneBstuff', 'assets/pics/ra-einstein.png');
this.load.on('complete', ()=>{
    //ENABLE ABILITY TO GO TO SCENE B
});
this.load.start();

Note: If your game isn’t huge, I would suggest just creating a preload scene and loading all of the assets for your game there. The preload scene could simply have a progress bar to indicate when the assets have loaded and then progress you to your first scene and you won’t have to worry about preloading anything afterwards.

3 Likes

Thanks jake ,it works.