[TUT + Code] Game State

Posts 14 of 4 · Page 1 of 1
[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:
Code:
private enum Screen
{
Menu, Lobby, Game
}
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.
Code:
Screen mCurrentScreen = Screen.Menu;
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)
Code:
KeyboardState e = Keyboard.GetState();
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:
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 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.
Code:
switch (mCurrentScreen)
{
case Screen.Menu: {
break;
} case Screen.Lobby: {
break;
} case Screen.Game: {
break;
}
}
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
Lmao.. This is poor.. seriously.

Is this a case tutorial? or..? you really didn't explain anything special.. and There is really good tutorials about GameState at XNACreators.. :\
Quote Originally Posted by 'Bruno View Post
Lmao.. This is poor.. seriously.

Is this a case tutorial? or..? you really didn't explain anything special.. and There is really good tutorials about GameState at XNACreators.. :\
Well why don't you make any tutorials then?
Quote Originally Posted by tuve2 View Post
Well why don't you make any tutorials then?
Obvious reason is obvious..

So i won't get a bad comment like you did
Posts 14 of 4 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?