NetworkStateManagementGame.cs 2.7 KB

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