Want more features on Pastebin? Sign Up, it's FREE!
Guest

PressStartScreen

By: a guest on May 15th, 2012  |  syntax: C#  |  size: 3.32 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. using EasyStorage;
  5.  
  6.  
  7. namespace Pong
  8. {  
  9.     class PressStartScreen : MenuScreen
  10.     {
  11.         IAsyncSaveDevice saveDevice;
  12.         public PressStartScreen()
  13.             : base("")
  14.         {
  15.             MenuEntry startMenuEntry = new MenuEntry("Press A to start");
  16.             startMenuEntry.Selected += StartMenuEntrySelected;
  17.             MenuEntries.Add(startMenuEntry);
  18.         }
  19.         void StartMenuEntrySelected(object sender, PlayerIndexEventArgs e)
  20.         {
  21.             PromptMe();
  22.         }
  23.         private void PromptMe()
  24.         {
  25.             // we can set our supported languages explicitly or we can allow the
  26.             // game to support all the languages. the first language given will
  27.             // be the default if the current language is not one of the supported
  28.             // languages. this only affects the text found in message boxes shown
  29.             // by EasyStorage and does not have any affect on the rest of the game.
  30.             EasyStorageSettings.SetSupportedLanguages(Language.English);
  31.             // on Windows Phone we use a save device that uses IsolatedStorage
  32.             // on Windows and Xbox 360, we use a save device that gets a
  33.             //shared StorageDevice to handle our file IO.
  34.             // create and add our SaveDevice
  35.             SharedSaveDevice sharedSaveDevice = new SharedSaveDevice();
  36.             ScreenManager.Game.Components.Add(sharedSaveDevice);
  37.             // make sure we hold on to the device
  38.             saveDevice = sharedSaveDevice;
  39.             // hook two event handlers to force the user to choose a new device if they cancel the
  40.             // device selector or if they disconnect the storage device after selecting it
  41.             sharedSaveDevice.DeviceSelectorCanceled +=
  42.                 (s, e) => e.Response = SaveDeviceEventResponse.Force;
  43.             sharedSaveDevice.DeviceDisconnected +=
  44.                 (s, e) => e.Response = SaveDeviceEventResponse.Force;
  45.             // prompt for a device on the first Update we can
  46.             sharedSaveDevice.PromptForDevice();
  47.             sharedSaveDevice.DeviceSelected += (s, e) =>
  48.             {
  49.                 //Save our save device to the global counterpart, so we can access it
  50.                 //anywhere we want to save/load
  51.                 Global.SaveDevice = (SaveDevice)s;
  52.                 //Once they select a storage device, we can load the main menu.
  53.                 //You'll notice I hard coded PlayerIndex.One here. You'll need to
  54.                 //change that if you plan on releasing your game. I linked to an
  55.                 //example on how to do that but here's the link if you need it.
  56.                 //<a href="http://blog.nickgravelyn.com/2009/03/basic-handling-of-multiple-controllers/">http://blog.nickgravelyn.com/2009/03/basic-handling-of-multiple-controllers/</a>
  57.                 //We need to perform a check to see if we're on the Press Start Screen.
  58.                 //If a storage device is selected NOT from this page, we don't want to
  59.                 //create a new Main Menu screen! (Thanks @FreelanceGames for the mention)
  60.                 if(this.IsActive)
  61.                     ScreenManager.AddScreen(new MainMenuScreen(), null);
  62.             };
  63.         }
  64.     }
  65. }
clone this paste RAW Paste Data