I want to make a start screen in monogame, where nothing happens in the game until button is pressed to start
So basically, i want to make a menu style screen where it's a title screen and no game mechanics start in the background such as timers or other process until player presses space to be prompted. to actually start the game, and i do not want this to be done with enum's or something overly complicated but just simple title screen prompting the user to continue.
i have and end title screen but i can't find a neat solution to do it for the start
below is what i have for the ending
any suggestions are appreciated
if (!player.dead)
player.animation.Draw(_spriteBatch);
if (!player.dead)
{
_spriteBatch.DrawString(MainFont, $"Time survived: {timer.ToString("F3")}",new Vector2(player.Position.X - 240, player.Position.Y + 270), Color.White);
}
else
{
_spriteBatch.Draw(endScreen, new Vector2(player.Position.X -900, player.Position.Y - 700), Color.White);
_spriteBatch.DrawString(MainFont, "YOU DIED", new Vector2(player.Position.X - 155.0f, player.Position.Y - 70), Color.Gold);
_spriteBatch.DrawString(MainFont, "PRESS ESCAPE TO EXIT", new Vector2(player.Position.X - 325.0f, player.Position.Y + -10.0f), Color.Gold);
_spriteBatch.DrawString(MainFont, $"Time Survived: {timer.ToString("F3")}", new Vector2(player.Position.X - 280.0f, player.Position.Y + 50.0f), Color.White);
// Creates a formatted string with the current timer value, including to the decimal place you want for this example its 3.
//$ indicates that the string will contain expressions, and the expressions will be evaluated and inserted into the string.
}
There are several ways to do this. You don't need to use an enum but it's a bit more readable that way.
You could use a rather simple form of a state machine with all different states the game could be in: Menu, Playing, Paused, Game Over. Usually, you'd have a method to switch between those states and trigger all the related effects, UI and the like:
Setting the state would happen where the Input is handled, like escape key for opening the menu (pause and menu are often one state by the way), hitting escape again would close and resume. Dying would set the game over state and so on.
Rendering the different states in any way stays similar to your method, you'd just check which game state is active. This can even be a method with the same switch inside the GameSession class, then called from where the drawing happens (I can add this if you want). You could also use objects (which would be instantiated as soon as needed) for the menu, game over screen etc but that is a bit more complicated.
This stays expandable and keeps your code structured. Let me know if this was useful to you!