fitness23 Posted June 20, 2017 Share Posted June 20, 2017 So I have my main game state called "Game" and I need to allow the user to go to another state called "Volume". I can make the user go to the "Volume" state all fine, but when I try going back to "Game" state by doing: this.state.start('Game'); all the functions I put in the Create function get re-run and the player has to start from the beginning again. I need the game to remember where the player was standing, where the enemies were etc, without the state restarting. Any ideas? Link to comment Share on other sites More sharing options...
spencerTL Posted June 20, 2017 Share Posted June 20, 2017 Phaser2 can't have simultaneous states so you need to save the character coordinates etc to a global variable and reconstruct it when you change back to the original state. Alternatively, you could bring in the other state's functions to the original state. If your volume state is just, say, a volume slider, then create that as a group and control its visibility instead of switching states. Save the volume variable to global to access across other states. Phaser 3 is reported to have simultaneous states but it's a way off yet. Link to comment Share on other sites More sharing options...
fitness23 Posted June 20, 2017 Author Share Posted June 20, 2017 3 minutes ago, spencerTL said: Phaser2 can't have simultaneous states so you need to save the character coordinates etc to a global variable and reconstruct it when you change back to the original state. Alternatively, you could bring in the other state's functions to the original state. If your volume state is just, say, a volume slider, then create that as a group and control its visibility instead of switching states. Save the volume variable to global to access across other states. Phaser 3 is reported to have simultaneous states but it's a way off yet. Cool thanks for the reply. The grouping and visibility would be a lot easier! But how would I pause the game behind it whilst the user is fiddling with the Volume level? Link to comment Share on other sites More sharing options...
ncil Posted June 20, 2017 Share Posted June 20, 2017 I think the best way to pause the game would be to create your own pause function that freezes the player's controls, movement, enemy movement, etc. It is kind of annoying but it will give you the most control in the long run. The typical game.paused = true is probably not the right solution. Link to comment Share on other sites More sharing options...
Recommended Posts