GameScreen.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.Graphics;
  5. namespace MonoGame.Extended.Screens;
  6. /// <summary>
  7. /// Provides an abstract base class for game screens that require access to core game services and components.
  8. /// </summary>
  9. /// <remarks>
  10. /// <para>
  11. /// The <see cref="GameScreen"/> class extends <see cref="Screen"/> by providing convenient access to commonly
  12. /// used game services such as the content manager, graphics device, and service container. This eliminates
  13. /// the need for derived screens to manually access these services through the game instance.
  14. /// </para>
  15. /// </remarks>
  16. public abstract class GameScreen : Screen
  17. {
  18. /// <summary>
  19. /// Gets the game instance associated with this screen that provides access to core services and components.
  20. /// </summary>
  21. public Game Game { get; }
  22. /// <summary>
  23. /// Gets the content manager for loading game assets.
  24. /// </summary>
  25. public ContentManager Content => Game.Content;
  26. /// <summary>
  27. /// Gets the graphics device for rendering operations.
  28. /// </summary>
  29. public GraphicsDevice GraphicsDevice => Game.GraphicsDevice;
  30. /// <summary>
  31. /// Gets the service container for accessing registered game services.
  32. /// </summary>
  33. public GameServiceContainer Services => Game.Services;
  34. /// <summary>
  35. /// Initializes a new instance of the <see cref="GameScreen"/> class.
  36. /// </summary>
  37. /// <param name="game">The game instance that provides access to core services.</param>
  38. /// <exception cref="ArgumentNullException">
  39. /// Thrown when <paramref name="game"/> is <see langword="null"/>.
  40. /// </exception>
  41. protected GameScreen(Game game)
  42. {
  43. ArgumentNullException.ThrowIfNull(game);
  44. Game = game;
  45. }
  46. }