Game.cs 2.1 KB

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