ForgeableSum Posted December 5, 2015 Share Posted December 5, 2015 Is there a way to prevent Phaser from destroying the cache when going from 1 game state to another? I already tried:game.cache.destroy = null; I also tried setting clearWorld and clearCache (internal booleans) to false when starting the new state:game.state.start("New State",false,false); And yet, the cache still gets wiped. I tried going through every instance (in Phaser) of cache.destroy and commenting it out ... yet still the cache does not carry over from 1 state to the next! Link to comment Share on other sites More sharing options...
drhayes Posted December 6, 2015 Share Posted December 6, 2015 When you say cache... do you mean the thing that you load a bunch of images into in a preload state and then use in your main state, the assets cache? 'Cuz I know that works. Do you have a minimal example that reproduces this? Link to comment Share on other sites More sharing options...
ForgeableSum Posted December 6, 2015 Author Share Posted December 6, 2015 Yes, the game assets cache, e.g. game.cache._images. game.cache._json, etc. When you say "i know that works" are you saying that the cache does not automatically be destroyed when you go from one cache to another? What works? When I mean states, I don't mean going from preload to create, etc inside of a single state. I mean going from one state to a complete different state. I want one state to have access to the assets loaded in the preload of another state. Link to comment Share on other sites More sharing options...
drhayes Posted December 7, 2015 Share Posted December 7, 2015 Yes, sorry, I meant "moving from one state to another does not empty the asset cache". My game, running Phaser 2.4.4, preloads in one state, has a main menu in a second, then plays in a third... all using assets loaded in the first preload state. I'm kind of at a loss as to why that's happening for you, especially if you're commenting out all the "empty" and "destroy" methods and it's still happening. Can you make it happen in a minimal example on codepen or jsbin or something? Link to comment Share on other sites More sharing options...
ForgeableSum Posted December 10, 2015 Author Share Posted December 10, 2015 Yes, sorry, I meant "moving from one state to another does not empty the asset cache". My game, running Phaser 2.4.4, preloads in one state, has a main menu in a second, then plays in a third... all using assets loaded in the first preload state. I'm kind of at a loss as to why that's happening for you, especially if you're commenting out all the "empty" and "destroy" methods and it's still happening. Can you make it happen in a minimal example on codepen or jsbin or something?Please see my comment here: http://www.html5gamedevs.com/topic/18995-webgl-invalid-image-error/#entry108664 Link to comment Share on other sites More sharing options...
ekeimaja Posted December 10, 2015 Share Posted December 10, 2015 True clears world, and false keeps cache.this.game.state.start('level-id', true, false); Link to comment Share on other sites More sharing options...
in mono Posted December 10, 2015 Share Posted December 10, 2015 True clears world, and false keeps cache.this.game.state.start('level-id', true, false);Isn't this the default behaviour? I think it has been so for several versions already - http://phaser.io/docs/2.4.4/Phaser.StateManager.html#startIf you call justthis.game.state.start('level-id');you should get the same results. Link to comment Share on other sites More sharing options...
drhayes Posted December 10, 2015 Share Posted December 10, 2015 Just to close the loop here, too: in the code sample you linked to, don't transition to the next state at the end of the preload function in Boot, do it at the end of create instead. "create" is only called when preload is complete. That's how Blaster does it. in mono and ForgeableSum 2 Link to comment Share on other sites More sharing options...
Recommended Posts