pimous Posted March 27, 2015 Share Posted March 27, 2015 Hi everyone, I would like to create a game with several levels. I am a newbie with phaser, I only create games with one level. So what are the best practices to make a multilevel game ? There is a neat architecture for that ? Pooya72 1 Link to comment Share on other sites More sharing options...
pimous Posted April 1, 2015 Author Share Posted April 1, 2015 Nobody has an answer ? Link to comment Share on other sites More sharing options...
corpsefilth Posted April 3, 2015 Share Posted April 3, 2015 It's all about states, you can create several levels as states, then you can do it by score or after killing a big enemy ( boss fight ). So for example, in you main game state ( single level game ), you can check if score is more that 500, 000 for example, so you can create a function that is checking score and after score reached a certain amount 500,000 in our example, you can call another state. For example here is in my main menu state, If a user clicks on screen or touches screen then we load our Stage1 state, which will be level 1: update: function() { if(this.game.input.activePointer.justPressed()) { this.game.state.start('Stage1'); } } Afterwards in our level 1 state we can create another function: checkScore: function(score) { if(score > 500000) { this.game.state.start('Stage2'); }} and so on, let me know if this helps. Check out this great tutorial on game states: http://www.emanueleferonato.com/2014/08/28/phaser-tutorial-understanding-phaser-states/ Pooya72 1 Link to comment Share on other sites More sharing options...
fariazz Posted April 9, 2015 Share Posted April 9, 2015 You can keep all the level data in a JSON object, and pass the level to the GameState as a parameter. You can basically use the same State for multiple levels in this way:var levelX = { playerStartPosition: {x: 100, y: 20}, enemies: [ {x: 10, y: 10}, {x: 10, y: 20}, {x: 10, y: 30}, {x: 10, y: 4}], speed: 3, goalPosition: {x: 199, y:200}}Then when you launch your state (let's call it GameState)://The first “true” is because we want to refresh the game world, the second is set to “false” as we don’t want to erase the game’s cache//you pass it then the level data as a parameterthis.state.start('GameState', true, false, levelX)In a State, you read the parameter that was passed by using the init() method:init: function(levelData) { this.levelData = levelData;}..create: function() { //in here you place the level player, enemies and goal etc according to this.levelData..} Pooya72 1 Link to comment Share on other sites More sharing options...
Recommended Posts