2
0

Game.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 MonoMac.Foundation;
  13. using MonoMac.AppKit;
  14. using MonoMac.ObjCRuntime;
  15. #endregion
  16. namespace GameStateManagement
  17. {
  18. /// <summary>
  19. /// Sample showing how to manage different game states, with transitions
  20. /// between menu screens, a loading screen, the game itself, and a pause
  21. /// menu. This main game class is extremely simple: all the interesting
  22. /// stuff happens in the ScreenManager component.
  23. /// </summary>
  24. public class GameStateManagementGame : 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. };
  35. #endregion
  36. #region Initialization
  37. /// <summary>
  38. /// The main game constructor.
  39. /// </summary>
  40. public GameStateManagementGame ()
  41. {
  42. Content.RootDirectory = "Content";
  43. graphics = new GraphicsDeviceManager (this);
  44. graphics.PreferredBackBufferWidth = 853;
  45. graphics.PreferredBackBufferHeight = 480;
  46. // Create the screen manager component.
  47. screenManager = new ScreenManager (this);
  48. Components.Add (screenManager);
  49. // Activate the first screens.
  50. screenManager.AddScreen (new BackgroundScreen (), null);
  51. screenManager.AddScreen (new MainMenuScreen (), null);
  52. }
  53. /// <summary>
  54. /// Loads graphics content.
  55. /// </summary>
  56. protected override void LoadContent ()
  57. {
  58. foreach (string asset in preloadAssets) {
  59. Content.Load<object> (asset);
  60. }
  61. }
  62. #endregion
  63. #region Draw
  64. /// <summary>
  65. /// This is called when the game should draw itself.
  66. /// </summary>
  67. protected override void Draw (GameTime gameTime)
  68. {
  69. graphics.GraphicsDevice.Clear (Color.Black);
  70. // The real drawing happens inside the screen manager component.
  71. base.Draw (gameTime);
  72. }
  73. #endregion
  74. }
  75. #region Entry Point
  76. static class Program
  77. {
  78. /// <summary>
  79. /// The main entry point for the application.
  80. /// </summary>
  81. static void Main (string[] args)
  82. {
  83. NSApplication.Init ();
  84. using (var p = new NSAutoreleasePool ()) {
  85. NSApplication.SharedApplication.Delegate = new AppDelegate();
  86. NSApplication.Main(args);
  87. }
  88. }
  89. }
  90. class AppDelegate : NSApplicationDelegate
  91. {
  92. public override void FinishedLaunching (MonoMac.Foundation.NSObject notification)
  93. {
  94. using (GameStateManagementGame game = new GameStateManagementGame ()) {
  95. game.Run ();
  96. }
  97. }
  98. public override bool ApplicationShouldTerminateAfterLastWindowClosed (NSApplication sender)
  99. {
  100. return true;
  101. }
  102. }
  103. #endregion
  104. }