That's an OK way to do it. The way I do is that I have a ScreenManagerScreenManager
which "loads" screens, those screens are implementing the IScreenIScreen
interface and has different methods like LoadContentLoadContent
, UnloadContentUnloadContent
and InitializeInitialize
.
For instance, when I press the PLAY button in the main menu, the ScreenManager'sScreenManager
's addScreenaddScreen
function runs, sets the oldScreenoldScreen
variable's value to the newScreen'snewScreen
's value(in this example the main menu screen is becoming the oldScreenoldScreen
) and creates, loads the new screen whilst "Unloading" the previous one. (Note that I am using a loading screen)
The when the unloading is done, and the LoadContentLoadContent
sets the ScreenManager'sScreenManager
's state to DONE, the ScreenManagerScreenManager
is waiting for the user's input (press any key to continue). When it finally gets the input, the ScreenManagerScreenManager
intializes the newScreennewScreen
and removes the loading graphics.
Edit:
In In my ScreenManagerScreenManager
, restarting is nothing else but calling the addScreenaddScreen
function of my ScreenManagerScreenManager
.