awbummer Posted September 23, 2015 Share Posted September 23, 2015 Hi, Is it possible to preload assets within a state's create() function? I'd like to preload some stuff for the following state during gameplay in order to reduce load time, but when I attempt this, I get the following error: Phaser.Loader - aborting: processing queue empty, loading may have stalled Thanks! Link to comment Share on other sites More sharing options...
rich Posted September 23, 2015 Share Posted September 23, 2015 The most common way to handle this is to have a Preload state. Then use the 'preload' method to load all the assets you need, and in 'create' you can then change state to your main menu / game / whatever. Link to comment Share on other sites More sharing options...
awbummer Posted September 23, 2015 Author Share Posted September 23, 2015 Hey thanks for the reply! I use preload states as well. There's a good chance I'm not implementing them correctly, but this doesn't seem to reduce the overall load time experienced by the player. I'm wondering if there's a way to load assets concurrent with gameplay, while update() is actively cycling and the player has control. In pseudocode, here's what I'm trying to achieve:preloadState.preload = function(){ //load assets for state1 only; offset preload of state2 assets to state1.create()};preloadState.create = function(){ //load state1};state1.create = function(){ //use assets loaded in preloadState //begin downloading assets for state2 //load state2 when character exits bounds};state2.preload = function(){ //if assets aren't in the game's cache, load them now; otherwise do nothing}state2.create = function(){ //use assets that were loaded during gameplay in state1; or, if the character didn't hang out in state1 bounds for long enough, were loaded in state2.preload};I'm specifically trying to download and decode audio during gameplay. I attempted a workaround by preloading assets with jQuery from within the previous state's create() method so that it would be cached in the browser when game.load() got called in the following state. This effectively cached the audio, but when the same file was then loaded using game.load in the following state, it took just as long to download and decode (I determined this by keeping an eye on the network timeline in Chrome Developer Tools). Am I misunderstanding the function of the preload state? Link to comment Share on other sites More sharing options...
Recommended Posts