97 lines
No EOL
3.1 KiB
C#
97 lines
No EOL
3.1 KiB
C#
using System;
|
|
using Microsoft.Xna.Framework;
|
|
using Microsoft.Xna.Framework.Content;
|
|
using Microsoft.Xna.Framework.Graphics;
|
|
using MonoGameLibrary.Input;
|
|
|
|
namespace MonoGameLibrary;
|
|
|
|
public class Core : Game
|
|
{
|
|
internal static Core s_instance;
|
|
|
|
/// <summary>
|
|
/// Gets a reference to the Core instance.
|
|
/// </summary>
|
|
public static Core Instance => s_instance;
|
|
|
|
/// <summary>
|
|
/// Gets the graphics device manager to control the presentation of graphics.
|
|
/// </summary>
|
|
public static GraphicsDeviceManager graphics { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the graphics device used to create graphical resources and perform primitive rendering.
|
|
/// </summary>
|
|
public static new GraphicsDevice graphicsDevice { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the sprite batch used for all 2D rendering.
|
|
/// </summary>
|
|
public static SpriteBatch spriteBatch { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Gets the content manager used to load global assets.
|
|
/// </summary>
|
|
public static new ContentManager content { get; private set; }
|
|
|
|
/// <summary>
|
|
/// Creates a new Core instance.
|
|
/// </summary>
|
|
/// <param name="title">The title to display in the title bar of the game window.</param>
|
|
/// <param name="width">The initial width, in pixels, of the game window.</param>
|
|
/// <param name="height">The initial height, in pixels, of the game window.</param>
|
|
/// <param name="fullScreen">Indicates if the game should start in fullscreen mode.</param>
|
|
public Core(string title, int width, int height, bool fullScreen)
|
|
{
|
|
// Ensure that multiple cores are not created.
|
|
if (s_instance != null)
|
|
{
|
|
throw new InvalidOperationException($"Only a single Core instance can be created");
|
|
}
|
|
|
|
// Store reference to engine for global member access.
|
|
s_instance = this;
|
|
|
|
// Create a new graphics device manager.
|
|
graphics = new GraphicsDeviceManager(this);
|
|
|
|
// Set the graphics defaults.
|
|
graphics.PreferredBackBufferWidth = width;
|
|
graphics.PreferredBackBufferHeight = height;
|
|
graphics.IsFullScreen = fullScreen;
|
|
|
|
// Apply the graphic presentation changes.
|
|
graphics.ApplyChanges();
|
|
|
|
// Set the window title.
|
|
Window.Title = title;
|
|
|
|
// Set the core's content manager to a reference of the base Game's
|
|
// content manager.
|
|
content = base.Content;
|
|
|
|
// Set the root directory for content.
|
|
content.RootDirectory = "Content";
|
|
|
|
// Mouse is visible by default.
|
|
IsMouseVisible = true;
|
|
}
|
|
|
|
protected override void Initialize()
|
|
{
|
|
base.Initialize();
|
|
|
|
// Set the core's graphics device to a reference of the base Game's
|
|
// graphics device.
|
|
graphicsDevice = base.GraphicsDevice;
|
|
|
|
// Create the sprite batch instance.
|
|
spriteBatch = new SpriteBatch(graphicsDevice);
|
|
}
|
|
|
|
protected override void Update(GameTime gameTime) {
|
|
InputManager.NextInputCycle();
|
|
base.Update(gameTime);
|
|
}
|
|
} |