Game.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // Game.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using Microsoft.Xna.Framework;
  11. using Microsoft.Xna.Framework.Graphics;
  12. #endregion
  13. namespace Microsoft.Xna.Samples.GameStateManagement
  14. {
  15. /// <summary>
  16. /// Sample showing how to manage different game states, with transitions
  17. /// between menu screens, a loading screen, the game itself, and a pause
  18. /// menu. This main game class is extremely simple: all the interesting
  19. /// stuff happens in the ScreenManager component.
  20. /// </summary>
  21. public class GameStateManagementGame : Game
  22. {
  23. #region Fields
  24. GraphicsDeviceManager graphics;
  25. ScreenManager screenManager;
  26. #if ZUNE
  27. int BufferWidth = 272;
  28. int BufferHeight = 480;
  29. #elif IPHONE
  30. int BufferWidth = 320;
  31. int BufferHeight = 480;
  32. #else
  33. int BufferWidth = 272;
  34. int BufferHeight = 480;
  35. #endif
  36. #endregion
  37. #region Initialization
  38. /// <summary>
  39. /// The main game constructor.
  40. /// </summary>
  41. public GameStateManagementGame()
  42. {
  43. Content.RootDirectory = "Content";
  44. graphics = new GraphicsDeviceManager(this);
  45. graphics.PreferredBackBufferWidth = BufferWidth;
  46. graphics.PreferredBackBufferHeight = BufferHeight;
  47. // Create the screen manager component.
  48. screenManager = new ScreenManager(this);
  49. Components.Add(screenManager);
  50. // Activate the first screens.
  51. screenManager.AddScreen(new BackgroundScreen(), null);
  52. screenManager.AddScreen(new MainMenuScreen(), null);
  53. }
  54. #endregion
  55. #region Draw
  56. /// <summary>
  57. /// This is called when the game should draw itself.
  58. /// </summary>
  59. protected override void Draw(GameTime gameTime)
  60. {
  61. graphics.GraphicsDevice.Clear(Color.Black);
  62. // The real drawing happens inside the screen manager component.
  63. base.Draw(gameTime);
  64. }
  65. #endregion
  66. }
  67. }