I'm trying to give my game an inventory scene that the player can go to at the press of a button. When they arrive at the scene, they can view their items, and press the same button to return to the previous scene.
I want the inventory scene to be accessible from all the other scenes, and I plan to use the switch method to get back to the previous scene.
this.scene.switch('previousSceneName');
The thing I don't know is how to make sure that the player always goes back to the specific scene they came from. So what do I put in the place of 'previousSceneName' to ensure that the player is always taken back to the right scene and not any other?
If it helps, I'm using Phaser 3 in VSCode employing arcade physics.
The easy solution is just keep a global variable/gamestate, where you save the game scene key before switching to the inventory (or on game scene entering ), and on the way back use that variable.
Short Demo:
switchdoesn't restart the scene