This code simply draws the background image to the screen. The code uses the SpriteBatch class from the Microsoft.Xna.Framewok.Graphics namespace to draw over the graphics device. It enables a group of sprites to be drawn using the same settings.
When this method is called, the gameTime argument contains the time that passed since the last call to Draw was made.
Now that we have a background screen, it is time to add a menu which will present the user with some interactivity. Create a new class called MainMenuScreen in the Screens folder you have previously created.
Open the new class file and add the following using statements at the top of the file.
Change the new class to derive from the MenuScreen class (another screen class that is defined in the code under the ScreenManager folder):
class MainMenuScreen : MenuScreen
Note: Did you remember to alter the class’s namespace as well?
Add the following constructor to the class. It will define what menu entries this menu screen will display:
IsPopup = true;
// Create our menu entries.
MenuEntry startGameMenuEntry = new MenuEntry("Play");
MenuEntry exitMenuEntry = new MenuEntry("Exit");
// Hook up menu event handlers.
startGameMenuEntry.Selected += StartGameMenuEntrySelected;
exitMenuEntry.Selected += OnCancel;
// Add entries to the menu.
A menu screen contains MenuEntry objects which depict the menu’s items. Each entry contains an event handler, which fires when the user selects the entry from the menu. You can see how the above code sets the handlers for both menu entries. In the next step, we will add the
Page | 25