Ryan Posted January 22, 2014 Share Posted January 22, 2014 Hey guys, I've been reading through the docs trying to find the best way to do scenes, such as 'preloeader', 'menu', 'game' etc. that act in the same way they do in Flash. Do I create different stages for each scene? Do I create a group for each scene and simply hide and show the one I need? Any thoughts are welcome. Thanks! FyreTale Link to comment Share on other sites More sharing options...
neon Posted January 22, 2014 Share Posted January 22, 2014 phaser has a concept of states that you can use to manage your scenes Look in the repository under wip/examples/state. There you find directly an example with preloader,menu and game state Link to comment Share on other sites More sharing options...
Biggerplay Posted January 22, 2014 Share Posted January 22, 2014 Hey guys, I've been reading through the docs trying to find the best way to do scenes, such as 'preloeader', 'menu', 'game' etc. that act in the same way they do in Flash. Do I create different stages for each scene? Do I create a group for each scene and simply hide and show the one I need? Any thoughts are welcome. Thanks! FyreTale I'm completely new to Phaser, but from what I've read so far my approach is just going to be use groups like you suggested, and throw everything that's needed into a group and then add/remove them when needed. Link to comment Share on other sites More sharing options...
@99golems Posted January 22, 2014 Share Posted January 22, 2014 i'm using Phaser.State and Phaser.StateManager to handle switching scenes. They work almost exactly how I want them to work, except I had to shoehorn in onEntry() and onExit() methods because they don't have them by default and that's how I roll game states. Link to comment Share on other sites More sharing options...
Arlefreak Posted January 22, 2014 Share Posted January 22, 2014 There is a template that has Boot Preloader Menu Game on the repo phaser / resources / Project Templates / Basic Biggerplay 1 Link to comment Share on other sites More sharing options...
Biggerplay Posted January 22, 2014 Share Posted January 22, 2014 I don't suppose anyone has combined this with the above basic template? plicatibu 1 Link to comment Share on other sites More sharing options...
Chimera Posted January 22, 2014 Share Posted January 22, 2014 Doesn't the basic template already separate the different states using individual objects? The difference between the tutorial (not using states) and the basic template is how the objects are accessed I think. In the tutorial they are all called in the original game object using the preload, create, and update methods. In the basic template the objects are called by initiating the state. game.state.add('Boot', BasicGame.Boot);game.state.add('Game' BasicGame.Game);game.state.start(Boot); The state 'Boot' is initialized after running the start method, then within the Boot object you define your current state, and can move again to another state/object by referencing the next defined state to start. Instead of referencing all of the objects within the game, you are running each object independently or calling them based on your states requirements. If your game state requires an object not loaded, then you could use the example in the tutorial and run the preload method within your current states preload. This is as much for my education as yours, this is my interpretation so far, so if I am wrong I look forward to a better explanation. Link to comment Share on other sites More sharing options...
Biggerplay Posted January 23, 2014 Share Posted January 23, 2014 Doesn't the basic template already separate the different states using individual objects? The difference between the tutorial (not using states) and the basic template is how the objects are accessed I think. In the tutorial they are all called in the original game object using the preload, create, and update methods. In the basic template the objects are called by initiating the state. game.state.add('Boot', BasicGame.Boot);game.state.add('Game' BasicGame.Game);game.state.start(Boot); The state 'Boot' is initialized after running the start method, then within the Boot object you define your current state, and can move again to another state/object by referencing the next defined state to start. Instead of referencing all of the objects within the game, you are running each object independently or calling them based on your states requirements. If your game state requires an object not loaded, then you could use the example in the tutorial and run the preload method within your current states preload. This is as much for my education as yours, this is my interpretation so far, so if I am wrong I look forward to a better explanation. In the example I linked to though the dev has actually created objects for the Player, Level and HUD, so I was wondering how to incorporate that into the basic template, I'm sure it's straightforward but seeing I'm new to JS I wondered if anyones already combined those. Link to comment Share on other sites More sharing options...
CodeGuppy Posted July 10, 2017 Share Posted July 10, 2017 Instead of putting all your code in the main game loop, just create separate "classes" for each scene and then implement a Scene Manager to invoke the correct object function based on the current scene. Recently, while using the p5.js library, I face this issue... So I created a p5.js Scene Manager logic to allow developers switch between scenes: http://www.codeavenger.com/2017/02/27/p5-SceneManager.html Of course ... you can implement this concept regardless if you are using p5.js or not. Example: The following objects contain each scene setup and main loop functions (e.g. setup and draw): function Intro() { this.setup = function() { } this.draw = function() { } this.keyPressed = function() { this.sceneManager.showScene( Game ); } } function Game() { this.setup = function() { } this.draw = function() { } } Link to comment Share on other sites More sharing options...
Recommended Posts