Class GameBase
- Namespace
- OmegaEngine
- Assembly
- OmegaEngine.dll
Automatically provides an Engine instance with a fullscreen-capable window, render loop, input handling, etc.
public abstract class GameBase : IDisposable
- Inheritance
-
GameBase
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
By using this class, you don't need to create a window, set up InputProviders, provide access to DebugConsole, etc. yourself.
You should override at least Initialize() and Render(double). This corresponds to the template method pattern.
Constructors
GameBase(string, Icon?, Image?, bool)
Sets up the Form. Call ToWindowed(Size) or ToFullscreen() and Run() afterwards.
protected GameBase(string name, Icon? icon = null, Image? background = null, bool stretch = false)
Parameters
name
stringThe name of the application for the title bar
icon
IconThe icon of the application for the title bar
background
ImageA background image for the window while loading
stretch
boolStretch
background
to fit the screen? (false
will center it instead)
Fields
Form
The internal form used as the Engine render-targets
protected readonly GameBase.GameForm Form
Field Value
Properties
Disposed
Has the game been shutdown?
[Browsable(false)]
public bool Disposed { get; }
Property Value
Engine
[LuaHide]
public Engine Engine { get; }
Property Value
Fullscreen
Is the game in fullscreen mode?
public bool Fullscreen { get; }
Property Value
KeyboardInputProvider
A default KeyboardInputProvider hooked up to the Form.
public KeyboardInputProvider KeyboardInputProvider { get; }
Property Value
Loading
Indicates the game is currently loading something and the user must wait.
public bool Loading { get; set; }
Property Value
Remarks
On Windows 7 and newer this will cause a neat taskbar animation.
MouseInputProvider
A default MouseInputProvider hooked up to the Form.
public MouseInputProvider MouseInputProvider { get; }
Property Value
TouchInputProvider
A default TouchInputProvider hooked up to the Form.
public TouchInputProvider TouchInputProvider { get; }
Property Value
Methods
AddInputReceiver(IInputReceiver)
Calls AddReceiver(IInputReceiver) for all default InputProviders.
public void AddInputReceiver(IInputReceiver receiver)
Parameters
receiver
IInputReceiverThe object to receive the commands.
ApplyGraphicsSettings()
Called when graphics settings from an external source need to be applied to the Engine
protected virtual void ApplyGraphicsSettings()
BuildEngineConfig(bool)
Called to generate an EngineConfig based on external settings
protected virtual EngineConfig BuildEngineConfig(bool fullscreen)
Parameters
fullscreen
boolShall the configuration be generated for fullscreen mode?
Returns
Crash()
Crashes the game for testing purposes
[LuaGlobal]
public static void Crash()
Debug()
Called when the debug form is to be displayed
[LuaHide]
public virtual void Debug()
Dispose()
Dispose the Engine, the internal windows form, etc.
public void Dispose()
Dispose(bool)
To be called by Dispose() and the object destructor.
protected virtual void Dispose(bool disposing)
Parameters
disposing
booltrue
if called manually and not by the garbage collector.
Exit()
Stops the render loop and closes the window
public void Exit()
~GameBase()
protected ~GameBase()
Initialize()
To be called after the window is ready and the Engine needs to be set up
protected virtual bool Initialize()
Returns
- bool
true
if the initialization worked,false
if it failed an the app must be closed
NewLua()
Creates a new LuaInterface.Lua instance with commonly used objects preloaded.
[LuaHide]
public virtual Lua NewLua()
Returns
- Lua
RemoveInputReceiver(IInputReceiver)
Calls RemoveReceiver(IInputReceiver) for all default InputProviders.
public void RemoveInputReceiver(IInputReceiver receiver)
Parameters
receiver
IInputReceiverThe object to no longer receive the commands.
Render(double)
Called when the next frame needs to be rendered.
protected virtual void Render(double elapsedTime)
Parameters
elapsedTime
doubleThe number of seconds that have passed since this method was last called.
ResetEngine()
Resets the Engine
[LuaGlobal(Description = "Resets the graphics engine")]
protected virtual void ResetEngine()
Run()
Shows the window and runs the render loop until Exit() is called.
[LuaHide]
public virtual void Run()
ToFullscreen()
Sets up the Form for fullscreen display
protected void ToFullscreen()
ToWindowed(Size)
Sets up the Form for normal windowed (non-fullscreen) mode
protected void ToWindowed(Size size)
Parameters
size
SizeThe window size
UpdateStatus(string)
Updates the current status of the loading process
protected void UpdateStatus(string message)
Parameters
message
stringThe new message to display