[TUT + Code] Game State
If your going to make a game menu and and all those things and with that I mean all menus in the game including the game screen that show up. Everything in the game that show up is a part of a screen. (Just the way I show this way to code this)
Add this code under the Game1 class:
This is just a sample I did. And here are 3 different screens it is the Menu, Lobby and the Game.
Now lets add what screen that it shall start showing.
Just add that code under the another one.
Now it will just show the starting screen and we cant do anything.
So lets add some controls to the game screens.
Go down to Update.
If you are going to make a computer game the add(if you haven't)
if your going to make it for xbox I wont go through the stuff in this tutorial.
Now you have setup the basic on the controls. So lets set the controls.
Add this code under the last code we added:
Now when you press space when you start the game you go to the Lobby screen. I think you can figure out the rest. Or just ask.
Now the last thing. Draw.
Go down to Draw.
and add the same code as in the update.
And in those you past/write the code...
I will make a video tutorial on this when I got time. Ask for help if you need. And yes Google isn't that helpful, on this.
// Tuve2
Add this code under the Game1 class:
Code:
private enum Screen
{
Menu,
Lobby,
Game}
Now lets add what screen that it shall start showing.
Code:
Screen mCurrentScreen = Screen.Menu;
Now it will just show the starting screen and we cant do anything.
So lets add some controls to the game screens.
Go down to Update.
If you are going to make a computer game the add(if you haven't)
Code:
KeyboardState e = Keyboard.GetState();
Now you have setup the basic on the controls. So lets set the controls.
Add this code under the last code we added:
Code:
switch (mCurrentScreen)
{
case Screen.Menu:
{
if (e.IsKeyDown(Keys.Space) == true)
{
mCurrentScreen = Screen.Lobby;}
break;}
case Screen.Lobby:
{
break;}
case Screen.Game:
{
break;}}
Now the last thing. Draw.
Go down to Draw.
and add the same code as in the update.
Code:
switch (mCurrentScreen)
{
case Screen.Menu:
{
break;}
case Screen.Lobby:
{
break;}
case Screen.Game:
{
break;}}
I will make a video tutorial on this when I got time. Ask for help if you need. And yes Google isn't that helpful, on this.
// Tuve2
