Jump to content

preloader wait on item complete before continuing


bajinaji
 Share

Recommended Posts

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

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

 Share

  • Recently Browsing   0 members

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