X hits on this document

225 views

0 shares

0 downloads

0 comments

25 / 102

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.

44.

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.

45.

Open the new class file and add the following using statements at the top of the file.

C#

using GameStateManagement;

using Microsoft.Xna.Framework;

46.

Change the new class to derive from the MenuScreen class (another screen class that is defined in the code under the ScreenManager folder):

C#

class MainMenuScreen : MenuScreen

{

}

Note: Did you remember to alter the class’s namespace as well?

47.

Add the following constructor to the class. It will define what menu entries this menu screen will display:

C#

public MainMenuScreen()

           : base(String.Empty)

{

   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.

   MenuEntries.Add(startGameMenuEntry);

   MenuEntries.Add(exitMenuEntry);

}

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

Document info
Document views225
Page views225
Page last viewedSun Dec 04 08:10:00 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments