bajinaji Posted March 22, 2015 Share Posted March 22, 2015 Apologies for the complex title, I wasn't sure how best to describe what I am looking for in a few words. Basically, I load a text file, which contains a list of images I wish to load. I want to wait for the text file to be loaded, then load the images, all while maintaining the preload state so I can ensure all textures are loaded before continuing to the create state. My code sample is below: PhaserGame.Game.prototype.preload = function () { // Load level var loader = game.load.json('level', 'level/level1.txt'); loader.onLoadComplete.addOnce(function(){ var level = game.cache.getJSON('level'); console.log('loaded level'); this.addLevelObjects(level); }, this);}; The level file is a json object that contains an array of images.The addLevelObjects method takes the list of items and then calls image.load on them. Sadly the preload function finishes as soon as the game.load completes, and the onloadcomplete is fired after transitioning to the create method. Any assistance much appreciated. Cheers, Rob Link to comment Share on other sites More sharing options...
rich Posted March 22, 2015 Share Posted March 22, 2015 Yes I do this often - the way I do it is to have a Boot State. That will load in the configuration file and whatever graphics the Preloader needs (like a background, logo and preload bar). Then once loaded I swap to a Preload state which loads all the rest of the assets. Link to comment Share on other sites More sharing options...
bajinaji Posted March 22, 2015 Author Share Posted March 22, 2015 Ta rich, I vaguely considered what you have proposed, but hoped there was a way to do this in a single state. Your answer is good, thank you Link to comment Share on other sites More sharing options...
rich Posted March 23, 2015 Share Posted March 23, 2015 These is a way to do it in a single state, but I would recommend the above approach instead personally, it's a lot cleaner. Link to comment Share on other sites More sharing options...
Recommended Posts