Jump to content

load assets after preload


Recommended Posts

Hi all, 

currently I got 2 state

stateA assetsA

stateB assetsB

I want to load assetsB after stateA create completed, so when I go to stateB the preload flow can be faster even to 0. 

so I wrote like this in the end of stateA create part
but I got some wranings


this.game.load.audio('stateB1', 'assets/audio/stateB1.ogg');

 Phaser.Loader - active loading canceled / reset ----phaser-2.6.2.js:74076 

and the assets are not loaded at all.


so do you guys now how should I do to 【preload】assets for next state, thx

Link to comment
Share on other sites

21 minutes ago, Fenopiù said:

In Phaser you could only preload assets in preload state, so if you want to load other assets after the end of stateA, you have to have another preload state where you preload your assetsB for stateB.

thx for reply, actually I don't want to load assets in the end of stateA, I  want to load during the stateA, is that possible? I think there should be some way to do it. but the loading always be reset

Link to comment
Share on other sites

You can try something like this:

let imagesToLoad = ['image1.png', 'image2.png', 'image3.png'];

... but because (naturally) the images won't load immediately, you have to attach a callback and wait for the loading to complete like this:

this.game.load.onLoadComplete.add(this.loadCompleted, this);

and then do your stuff in a method called 'loadCompleted' in the same state.

Haven't tested it, but it should work.

Edit: maybe you should attach the callback twice (once before and once after) if you want to try adding stuff to the load queue right after preload(). If something is already loading, the error is probably because you're calling start() when the loader is still running.

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...