Vaughan Posted February 19, 2014 Share Posted February 19, 2014 I'm working on a game where objects are spawned by players and I want to load the assets from the disk as they're created. I don't want to load everything up front. However, it seems like loading after the preload function dosen't actually seem to do add anything to the cache. It does not seem like loadTexture does anything, either. Link to comment Share on other sites More sharing options...
rich Posted February 19, 2014 Share Posted February 19, 2014 Split your game up into States. Each State can have its own preload. loadTexture is for loading a new texture onto a Sprite, not for loading it from disk, Link to comment Share on other sites More sharing options...
Vaughan Posted February 19, 2014 Author Share Posted February 19, 2014 I do have multiple states. While on the GameplayState, an object may be spawned already in the asset folder (there's a lot of them). It's added and loadTexture is called to load in the sprite. I want to fetch the sprite mid-game -- loading it all at once probably isn't a great idea. Or at the very least, I need a way to add sprites for an entire folder. Link to comment Share on other sites More sharing options...
rich Posted February 19, 2014 Share Posted February 19, 2014 It's really not a great idea to load data mid-play. Phaser obviously can't load a "folder", it has no concept of folders and as JavaScript can't read a filesystem it would be impossible anyway, so it's up to you to provide the list of files. But if you still want to go ahead you can call the Loader from any point. If you're doing it outside of preload then just add the assets via game.load.image() (or whatever), add a listener for when the load completes (game.load.onLoadComplete.add(yourFunc, this) and when the queue is ready just start it: game.load.start(). You may need to reset the loader first (load.reset), but I'm pretty sure it does that once the preload completes anyway. Link to comment Share on other sites More sharing options...
Vaughan Posted February 19, 2014 Author Share Posted February 19, 2014 If this is not how Phaser is designed, then I will attempt to avoid doing so.Thanks for your advice. Link to comment Share on other sites More sharing options...
rich Posted February 19, 2014 Share Posted February 19, 2014 Phaser can handle it, I'm just more worried about the impact it would have on your game at runtime. Link to comment Share on other sites More sharing options...
Recommended Posts