X hits on this document

277 views

0 shares

0 downloads

0 comments

26 / 102

methods that are specified as event handlers.

48.

Create the event handlers by implementing the following methods in the class:

C#

// Handles "Play" menu item selection

void StartGameMenuEntrySelected(object sender, EventArgs e)

{

   ScreenManager.AddScreen(new InstructionsScreen(), null);

}

// Handles "Exit" menu item selection

protected override void OnCancel(PlayerIndex playerIndex)

{

   ScreenManager.Game.Exit();

}

Notice the difference between the two method signatures. While StartGameMenuEntrySelected is an actual event handler, OnCancel is actually called from a different event handler, which is also called OnCancel and is implemented in the base class. Also, notice that StartGameMenuEntrySelected’s body adds a screen which we will soon create.

49.

Override the UpdateMenuEntryLocations method. This allows a menu screen to control the location of its menu items:

C#

protected override void UpdateMenuEntryLocations()

{

   base.UpdateMenuEntryLocations();

   foreach (var entry in MenuEntries)

   {

       var position = entry.Position;

       position.Y += 60;

       entry.Position = position;

   }

}

50.

Create a new class called InstructionsScreen in the Screens folder you have previously created.

51.

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

C#

using Microsoft.Xna.Framework.Graphics;

using Microsoft.Xna.Framework;

using GameStateManagement;

using Microsoft.Xna.Framework.Input.Touch;

52.

Change the new class to derive from the GameScreen class:

Page | 26

Document info
Document views277
Page views277
Page last viewedFri Dec 09 08:13:50 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments