Game.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. using Microsoft.Xna.Framework.GamerServices;
  13. using Microsoft.Xna.Framework.Net;
  14. #endregion
  15. namespace NetworkStateManagement
  16. {
  17. /// <summary>
  18. /// Sample showing how to manage the different game states involved in
  19. /// implementing a networked game, with menus for creating, searching,
  20. /// and joining sessions, a lobby screen, and the game itself. This main
  21. /// game class is extremely simple: all the interesting stuff happens
  22. /// in the ScreenManager component.
  23. /// </summary>
  24. public class NetworkStateManagementGame : Microsoft.Xna.Framework.Game
  25. {
  26. #region Fields
  27. GraphicsDeviceManager graphics;
  28. ScreenManager screenManager;
  29. // By preloading any assets used by UI rendering, we avoid framerate glitches
  30. // when they suddenly need to be loaded in the middle of a menu transition.
  31. static readonly string[] preloadAssets =
  32. {
  33. "gradient",
  34. "cat",
  35. "chat_ready",
  36. "chat_able",
  37. "chat_talking",
  38. "chat_mute",
  39. };
  40. #endregion
  41. #region Initialization
  42. /// <summary>
  43. /// The main game constructor.
  44. /// </summary>
  45. #if ANDROID
  46. public NetworkStateManagementGame (Activity activity) : base (activity)
  47. #else
  48. public NetworkStateManagementGame ()
  49. #endif
  50. {
  51. Content.RootDirectory = "Content";
  52. graphics = new GraphicsDeviceManager (this);
  53. #if ANDROID
  54. graphics.IsFullScreen = true;
  55. #else
  56. graphics.PreferredBackBufferWidth = 1067;
  57. graphics.PreferredBackBufferHeight = 600;
  58. #endif
  59. // Create components.
  60. screenManager = new ScreenManager (this);
  61. Components.Add (screenManager);
  62. Components.Add (new MessageDisplayComponent (this));
  63. Components.Add (new GamerServicesComponent (this));
  64. // Activate the first screens.
  65. screenManager.AddScreen (new BackgroundScreen (), null);
  66. screenManager.AddScreen (new MainMenuScreen (), null);
  67. // Listen for invite notification events.
  68. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted (screenManager, e);
  69. // To test the trial mode behavior while developing your game,
  70. // uncomment this line:
  71. // Guide.SimulateTrialMode = true;
  72. }
  73. /// <summary>
  74. /// Loads graphics content.
  75. /// </summary>
  76. protected override void LoadContent ()
  77. {
  78. foreach (string asset in preloadAssets) {
  79. Content.Load<object> (asset);
  80. }
  81. }
  82. #endregion
  83. #region Draw
  84. /// <summary>
  85. /// This is called when the game should draw itself.
  86. /// </summary>
  87. protected override void Draw (GameTime gameTime)
  88. {
  89. graphics.GraphicsDevice.Clear (Color.Black);
  90. // The real drawing happens inside the screen manager component.
  91. base.Draw (gameTime);
  92. }
  93. #endregion
  94. }
  95. }