If you don't have that many screens, you could instantiate each one as public fields in Game. (if you want you can write methods like getMapScreen() and getMenuScreen()). If each screen holds a reference to Game, then you can have a simple method in Game like.
1 2 3
| public void setScreen(GameScreen screen) { currentScreen = screen; } |
Then within your
mapScreen you could just call
game.setScreen(game.combatScreen);. You can make it a bit more sophisticated too. For instance if each screen has code that it needs run only when it's initialized or when it's closed, you can modify your setScreen code to somehting like:
1 2 3 4 5
| public void setScreen(GameScreen screen) { currentScreen.close(); currentScreen = screen; currentScreen.initialize(); } |