Jump to content

Level Loading approaches?


mokargas
 Share

Recommended Posts

Hey all,

I'm creating a basic platformer that loads levels from JSON files, output from the Tiled map maker http://www.mapeditor.org/. Currently I simply preload the first level JSON, and render it to screen.

This works really great. However, I have created 25 levels now (with a view to adding more), each with their own JSON files, so I'm considering more extensible and performant approaches to loading levels.

Reading the forums, it has been mentioned that creating a static state for each of these levels is too intensive, and I think preloading 50 JSON files to upfront is probably a bit intensive as well. 

I'm wondering how other Phaser devs handle this problem? 

 

Link to comment
Share on other sites

Add a param to the level state's init function ,load different level according to the param.


Game.Main.prototype = {
    init: function (lv) {
        level =lv;
    },

    create:function(){
        loadLevel(level);
    }
 //Codes...

And start the state:

game.state.start("Main",
    true, //clear world   
    true, //clear cache (loaded assets) 
    1 //param(s)
);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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