NetworkStateManagementGame.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. #if ANDROID
  39. public NetworkStateManagementGame (Activity activity) : base (activity)
  40. #else
  41. public NetworkStateManagementGame()
  42. #endif
  43. {
  44. Content.RootDirectory = "Content";
  45. graphics = new GraphicsDeviceManager(this);
  46. #if MOBILE
  47. graphics.IsFullScreen = true;
  48. #endif
  49. graphics.PreferredBackBufferWidth = 1067;
  50. graphics.PreferredBackBufferHeight = 600;
  51. // Create components.
  52. screenManager = new ScreenManager(this);
  53. Components.Add(screenManager);
  54. Components.Add(new MessageDisplayComponent(this));
  55. Components.Add(new GamerServicesComponent(this));
  56. // Activate the first screens.
  57. screenManager.AddScreen(new BackgroundScreen(), null);
  58. screenManager.AddScreen(new MainMenuScreen(), null);
  59. // Listen for invite notification events.
  60. NetworkSession.InviteAccepted += (sender, e) => NetworkSessionComponent.InviteAccepted(screenManager, e);
  61. // To test the trial mode behavior while developing your game,
  62. // uncomment this line:
  63. // Guide.SimulateTrialMode = true;
  64. }
  65. /// <summary>
  66. /// Loads graphics content.
  67. /// </summary>
  68. protected override void LoadContent()
  69. {
  70. foreach (string asset in preloadAssets)
  71. {
  72. Content.Load<object>(asset);
  73. }
  74. }
  75. /// <summary>
  76. /// This is called when the game should draw itself.
  77. /// </summary>
  78. protected override void Draw(GameTime gameTime)
  79. {
  80. graphics.GraphicsDevice.Clear(Color.Black);
  81. // The real drawing happens inside the screen manager component.
  82. base.Draw(gameTime);
  83. }
  84. }
  85. }