Class GameBase
The game.
public abstract class GameBase : ComponentBase, IDisposable, IComponent, IReferencable, ICollectorHolder, IGame
- Inheritance
-
GameBase
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
GameBase()
Initializes a new instance of the GameBase class.
protected GameBase()
Fields
Log
protected readonly ILogger Log
Field Value
graphicsDeviceManager
protected IGraphicsDeviceManager graphicsDeviceManager
Field Value
Properties
Content
Gets the ContentManager.
public ContentManager Content { get; }
Property Value
Context
Gets the game context.
public GameContext Context { get; }
Property Value
- GameContext
The game context.
DrawInterpolationFactor
Is used when we draw without running an update beforehand, so when both IsFixedTimeStep
and IsDrawDesynchronized are set.
It returns a number between 0 and 1 which represents the current position our DrawTime is in relation
to the previous and next step.
0.5 would mean that we are rendering at a time halfway between the previous and next fixed-step.
public float DrawInterpolationFactor { get; }
Property Value
- float
The draw interpolation factor.
DrawTime
The total and delta time to be used for logic running in the draw loop.
public GameTime DrawTime { get; }
Property Value
DrawWhileMinimized
Should this instance still render/draw when the window is minimized. Updates are still going to run regardless of the value set.
public bool DrawWhileMinimized { get; set; }
Property Value
ForceOneUpdatePerDraw
Gets or sets a value indicating whether this instance should force exactly one update step per one draw step
protected bool ForceOneUpdatePerDraw { get; set; }
Property Value
- bool
true
if this instance forces one update step per one draw step; otherwise,false
.
FullPlatformName
Gets the full name of the device this game is running if available
public string FullPlatformName { get; }
Property Value
GameSystems
Gets the game components registered by this game.
public GameSystemCollection GameSystems { get; }
Property Value
- GameSystemCollection
The game components.
GraphicsContext
Gets the graphics context.
public GraphicsContext GraphicsContext { get; }
Property Value
- GraphicsContext
The graphics context.
GraphicsDevice
Gets the graphics device.
public GraphicsDevice GraphicsDevice { get; }
Property Value
- GraphicsDevice
The graphics device.
InactiveSleepTime
public TimeSpan InactiveSleepTime { get; set; }
Property Value
- TimeSpan
The inactive sleep time.
IsActive
Gets a value indicating whether this instance is active.
public bool IsActive { get; }
Property Value
- bool
true
if this instance is active; otherwise,false
.
IsDrawDesynchronized
When IsFixedTimeStep is set, is it allowed to render frames between two steps when we have time to do so.
public bool IsDrawDesynchronized { get; set; }
Property Value
- bool
true
if this instance's drawing is desychronized ; otherwise,false
.
IsExiting
Gets a value indicating whether this instance is exiting.
public bool IsExiting { get; }
Property Value
- bool
true
if this instance is exiting; otherwise,false
.
IsFixedTimeStep
Gets or sets a value indicating whether the elapsed time between each update should be constant, see TargetElapsedTime to configure the duration.
public bool IsFixedTimeStep { get; set; }
Property Value
- bool
true
if this instance is fixed time step; otherwise,false
.
IsMouseVisible
Gets or sets a value indicating whether the mouse should be visible.
public bool IsMouseVisible { get; set; }
Property Value
- bool
true
if the mouse should be visible; otherwise,false
.
IsRunning
Gets a value indicating whether this instance is running.
public bool IsRunning { get; }
Property Value
LaunchParameters
Gets the launch parameters.
public LaunchParameters LaunchParameters { get; }
Property Value
- LaunchParameters
The launch parameters.
MinimizedMinimumUpdateRate
Access to the throttler used to set the minimum time allowed between each updates while the window is minimized and, depending on TreatNotFocusedLikeMinimized, while unfocused.
public ThreadThrottler MinimizedMinimumUpdateRate { get; }
Property Value
Services
Gets the service container.
public ServiceRegistry Services { get; }
Property Value
- ServiceRegistry
The service container.
TargetElapsedTime
Gets or sets the target elapsed time, this is the duration of each tick/update when IsFixedTimeStep is enabled.
public TimeSpan TargetElapsedTime { get; set; }
Property Value
- TimeSpan
The target elapsed time.
TreatNotFocusedLikeMinimized
Considers windows without user focus like a minimized window for MinimizedMinimumUpdateRate
public bool TreatNotFocusedLikeMinimized { get; set; }
Property Value
UpdateTime
The total and delta time to be used for logic running in the update loop.
public GameTime UpdateTime { get; }
Property Value
Window
Gets the abstract window.
public GameWindow Window { get; }
Property Value
- GameWindow
The window.
WindowMinimumUpdateRate
Access to the throttler used to set the minimum time allowed between each updates.
public ThreadThrottler WindowMinimumUpdateRate { get; }
Property Value
Methods
BeginDraw()
Starts the drawing of a frame. This method is followed by calls to Update(GameTime), Draw(GameTime) and EndDraw(bool).
protected virtual bool BeginDraw()
Returns
- bool
true
to continue drawing, false to not call Draw(GameTime) and EndDraw(bool)
BeginRun()
Called after all components are initialized, before the game loop starts.
protected virtual void BeginRun()
ConfirmRenderingSettings(bool)
public abstract void ConfirmRenderingSettings(bool gameCreation)
Parameters
gameCreation
bool
Destroy()
Disposes of object resources.
protected override void Destroy()
Draw(GameTime)
Reference page contains code sample.
protected virtual void Draw(GameTime gameTime)
Parameters
gameTime
GameTimeTime passed since the last call to Draw.
EndDraw(bool)
Ends the drawing of a frame. This method will always be preceeded by calls to BeginDraw() and perhaps Draw(GameTime) depending on if we had to do so.
protected virtual void EndDraw(bool present)
Parameters
present
bool
EndRun()
Called after the game loop has stopped running before exiting.
protected virtual void EndRun()
Exit()
Exits the game.
public void Exit()
Initialize()
Called after the Game is created, but before GraphicsDevice is available and before LoadContent(). Reference page contains code sample.
protected virtual void Initialize()
OnActivated(object, EventArgs)
Raises the Activated event. Override this method to add code to handle when the game gains focus.
protected virtual void OnActivated(object sender, EventArgs args)
Parameters
OnDeactivated(object, EventArgs)
Raises the Deactivated event. Override this method to add code to handle when the game loses focus.
protected virtual void OnDeactivated(object sender, EventArgs args)
Parameters
OnExiting(object, EventArgs)
Raises an Exiting event. Override this method to add code to handle when the game is exiting.
protected virtual void OnExiting(object sender, EventArgs args)
Parameters
OnWindowCreated()
protected virtual void OnWindowCreated()
PrepareContext()
Creates or updates Context before window and device are created.
protected virtual void PrepareContext()
RawTick(TimeSpan, int, float, bool)
Call this method within your overriden RawTickProducer() to update and draw the game yourself.
As this version is manual, there are a lot of functionality purposefully skipped:
clamping elapsed time to a maximum, skipping drawing when the window is minimized, ResetElapsedTime(), SuppressDraw(), IsFixedTimeStep,
IsDrawDesynchronized, MinimizedMinimumUpdateRate / WindowMinimumUpdateRate / TreatNotFocusedLikeMinimized.
protected void RawTick(TimeSpan elapsedTimePerUpdate, int updateCount = 1, float drawInterpolationFactor = 0, bool drawFrame = true)
Parameters
elapsedTimePerUpdate
TimeSpanThe amount of time passed between each update of the game's system, the total time passed would be
elapsedTimePerUpdate
*updateCount
.updateCount
intThe amount of updates that will be executed on the game's systems.
drawInterpolationFactor
floatdrawFrame
boolDraw a frame.
RawTickProducer()
Calls RawTick(TimeSpan, int, float, bool) automatically based on this game's setup, override it to implement your own system.
protected virtual void RawTickProducer()
ResetElapsedTime()
Resets the elapsed time counter.
public void ResetElapsedTime()
Run(GameContext)
Call this method to initialize the game, begin running the game loop, and start processing events for the game.
public void Run(GameContext gameContext = null)
Parameters
gameContext
GameContextThe window Context for this game.
Exceptions
- InvalidOperationException
Cannot run this instance while it is already running
ShowMissingRequirementMessage(Exception)
This is used to display an error message if there is no suitable graphics device or sound card.
protected virtual bool ShowMissingRequirementMessage(Exception exception)
Parameters
exception
ExceptionThe exception to display.
Returns
SuppressDraw()
Prevents calls to Draw until the next Update.
public void SuppressDraw()
Tick()
Updates the game's clock and calls Update and Draw.
public void Tick()
UnloadContent()
Called when graphics resources need to be unloaded. Override this method to unload any game-specific graphics resources.
protected virtual void UnloadContent()
Update(GameTime)
Reference page contains links to related conceptual articles.
protected virtual void Update(GameTime gameTime)
Parameters
gameTime
GameTimeTime passed since the last call to Update.
Events
Activated
Occurs when [activated].
public event EventHandler<EventArgs> Activated
Event Type
Deactivated
Occurs when [deactivated].
public event EventHandler<EventArgs> Deactivated
Event Type
Exiting
Occurs when [exiting].
public event EventHandler<EventArgs> Exiting
Event Type
UnhandledException
public event EventHandler<GameUnhandledExceptionEventArgs> UnhandledException
Event Type
WindowCreated
Occurs when [window created].
public event EventHandler<EventArgs> WindowCreated