Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I m new to XNA game programming(also C#). I want to create a main page with some buttons and when clicking on a particular button, it should go to another screen where there are some more buttons to select, which should in turn go to the game screen when clicked. Whether I can put all the code in "game1.cs" or create new class for every page. I just went through "Learning xna4.0" by O'Reilly. If there's any other good tutorials, please suggest me.

share|improve this question
3  
This is too vague to be answered. Try to expose your requirements, tell us what you've tried so far, what doesn't work... Check the faq for details on the kind of questions expected here. – Laurent Couvidou Oct 5 '12 at 10:11
If you are really expecting any answers, atleast write the question in proper english. From what I understand from your question, you are trying to create some sort of screen system where you have multiple screens ( or pages as you refer them ). Take a look at this: xbox.create.msdn.com/en-US/education/catalog/sample/… – Jaakko Lipsanen Oct 5 '12 at 10:52

closed as not a real question by Laurent Couvidou, Byte56, Jonathan Hobbs, Nicol Bolas, Tetrad Oct 13 '12 at 21:09

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, see the FAQ.

1 Answer

I found XNA Game Development By Example to be a great help for beginners.

That said, it's hard to answer your question because you provide relatively little detail, but what you want probably comes down to GameStates or a similar mechanic. It works roughly like this: You have a gamestate enum, a variable that contains info about what the game is (or should be) doing at the moment. For example, it could be one of the following options:

  • MainMenu
  • Playing
  • Pause
  • GameOver

Now in your Update and Draw methods, you check the gamestate via switch or if/else if/elseconstructions and based on that you do different things in your logic. For example, when it's set to MainMenu, you draw the main menu background, buttons, etc., and in the logic you watch out for button clicks. When it's set to Playing, you run the actual gameplay logic and draw the player, enemies, tiles, whatever is in your game, and so on.

This can of course be extended in several ways: you can use more gamestates, or you can have a kind of "sub-gamestate" contained in your menu that you manipulate with your buttons, so that you don't clutter your top level gamestate with options for each and every menu screen.

As to whether to put it all into your game1.cs file: it's basically possible, but so is chaining yourself to a train to get to work. It's usually better to structure your code in some way. For example, have a class for the menu, one for sprites, etc. That way, you don't get lost as easily once your game grows a bit.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.