Otter  0.9.8.91
2d Game Development Framework based on SFML.Net
 All Classes Namespaces Functions Variables Enumerations Properties
Otter.Game Class Reference

ᶜ(ᵔᴥᵔ)ᵓ Core class Otter. Create a Game, and then use Game.Start(); to run it. More...

Public Member Functions

 Game (string title="Game", int width=640, int height=480, int targetFramerate=60, bool fullscreen=false)
 Creates a new game to run in the program. More...
 
void SetWindow (int width, int height=0, bool fullscreen=false, bool vsync=false)
 Creates a new window for the game to be shown in. More...
 
void SetWindowAutoFullscreen (bool vsync=false)
 Creates a new window that is the resolution of the screen and in fullscreen mode. More...
 
void ForceDebugger ()
 Force the creation of a Debugger object (even in Release mode!) More...
 
void CenterWindow ()
 Center the window on the monitor that the window was initialized on. More...
 
void AddSurface (Surface surface)
 Add a surface to the list of surfaces to be rendered to the window. More...
 
void RemoveSurface (Surface surface)
 Remove a surface from the list of surfaces to be rendered to the window. More...
 
void SetWindowScale (float scale=1)
 Create a new window using a scale value instead of pixels. More...
 
void SetIcon (string source)
 Set the icon of the current window. More...
 
void Stop ()
 Stop the game from running completely. More...
 
void Pause ()
 Pause the game. More...
 
void Resume ()
 Resume the game after pausing. More...
 
void PauseToggle ()
 Toggle the pause state on and off. More...
 
void Sleep (int milliseconds)
 Pauses the game for a certain time. Only works with fixed framerate currently. More...
 
void Start (Scene firstScene)
 Start the game using a specific Scene. Shortcut for setting the FirstScene then using Start. More...
 
void Start ()
 Start the game. This will begin the game loop and no other code past Start() in your entry point will run. Make sure to set the first scene before executing this. More...
 
void Close ()
 Close the current game window. More...
 
void SwitchScene (Scene scene)
 Switch to a new scene. This removes the scene stack! More...
 
void AddScene (Scene scene)
 Add a scene to the top of the stack. You do not have to use Game.FirstScene if you use this before Game.Start(). More...
 
void AddScene (params Scene[] scenes)
 Add multiple scenes to the top of the stack. The last scene added will be on top. More...
 
void RemoveScene ()
 Remove the scene from the top of the scene stack. More...
 
GetScene< T > ()
 Get the current scene cast to a specific type. Useful for when you extend Scene to your own class. More...
 
Session AddSession (string name)
 Adds a new Session to the game. More...
 
Session AddSession (Enum name)
 Adds a new Session to the game. More...
 
Session Session (string name)
 Get a session by the name. More...
 
Session Session (Enum name)
 Get a Session by the name. More...
 
Session Session (int id)
 Get a session by id. More...
 

Public Attributes

int TargetFramerate
 The desired framerate that the game should update at. More...
 
bool FixedFramerate = true
 Render and update the game at a fixed framerate. The game will never exceed the target framerate, and will slow down if performance decreases. More...
 
string Title
 The title of the game displayed in the window. More...
 
bool Active = false
 If the game is currently being run. More...
 
bool Paused = false
 If the game is paused (no longer updating.) More...
 
Action OnInit = delegate { }
 An action called when the game initializes. More...
 
Action OnUpdate = delegate { }
 An action called when the game updates (happens after all Scene and Entity updates.) More...
 
Action OnSceneBegin = delegate { }
 An action called when any Scene begins. More...
 
Action OnSceneEnd = delegate { }
 An action called when any Scene ends. More...
 
Action OnEnd = delegate { }
 An Action called when the game ends. The last code that executes when closing the game. More...
 
Action OnFocusLost = delegate { }
 An action that is called when the window loses focus. More...
 
Action OnFocusGained = delegate { }
 An action that is called when the window gains focus. More...
 
Action OnEndOfUpdate = delegate { }
 An action that is called at the very end of the update (the very last thing before Render()) After this is called it will be cleared! More...
 
Action OnStartOfNextUpdate = delegate { }
 An action that is called at the very start of the next update (the very first thing before UpdateFirst()) After this is called it will be cleared! More...
 
bool DrawInactiveScenes = true
 If the game should draw all scenes on the stack including inactive scenes. More...
 
Color Color = Color.Black
 The default background color of the game. More...
 
Color LetterBoxColor = Color.Black
 The default color to draw in the letterboxed areas of the window. More...
 
float Timer
 How long the game has been active. Measured in units of delta time. More...
 
Scene FirstScene
 The first scene that the game should load when Start() is called. More...
 
int GameFrames
 The number of frames that have passed since the game started. If you're not using fixed framerate then this number will vary wildly. More...
 
bool MeasureTimeInFrames = true
 If the game should measure time in frames when using a fixed framerate. If true delta time will increase by 1 on each update, if false it will increase by 1 / TargetFramerate. More...
 
bool LockMouse
 If the game should attempt to lock the mouse inside the window. This is not 100% accurate. More...
 
int LockMousePadding = 10
 The distance from the edge of the window in which the mouse cant escape when locked. More...
 
bool LockMouseCenter
 If the mouse should be locked to the center of the window. The Input class should still report the mouse position accurately if this is true. This is currently the best way to lock the mouse inside of the window region. More...
 
bool AlwaysUpdate = true
 If the game should keep updating even when it has lost focus. More...
 
Atlas Atlas = new Atlas()
 The default Atlas to search for image assets in. More...
 
bool LockAspectRatio = true
 Maintain the original aspect ratio of the game when scaling the window. More...
 
Button QuitButton = new Button()
 Button that closes the game when pressed. Defaults to the Escape key. More...
 
Button ScreenshotButton = new Button()
 Button that will save the game's surface out to a timestamp named .png file after the next render. More...
 
bool EnableQuitButton = true
 Determines if the QuitButton can close the game. More...
 
bool EnableAltF4 = true
 Determines if Alt+F4 will close the game immediately. More...
 
bool InvertAngleY = true
 Determines if Y values determined by angles in the Util class will invert the Y axis. This is mostly for backwards compatibility. Turn it back to false if you don't want to change all of your math. More...
 
bool ReleaseModeDebugger = false
 Determines if the debug console will be available when building in release mode. Must be set before Game.Start() is called. More...
 
bool WindowResize = true
 Determines if the game window can be resized. Must be set before calling Game.SetWindow() or Game.Start(). More...
 
bool WindowClose = true
 Determines if the game window has a close button or Alt+F4. Must be set before calling Game.SetWindow() or Game.Start(). More...
 
bool WindowBorder = true
 Determines if the game window has a border. If the window has no border it cannot be resized or closed with the close button or Alt+F4. Must be set before calling Game.SetWindow() or Game.Start() More...
 

Static Public Attributes

static Game Instance
 A reference to the active Game instance. More...
 

Properties

int WindowX [get, set]
 Set the X position of the Window. More...
 
int WindowY [get, set]
 Set the Y position of the Window. More...
 
Debugger Debugger [get, set]
 The debugger. Only accessable in Debug mode, otherwise null. More...
 
Coroutine Coroutine [get, set]
 The Coroutine manager. More...
 
Tweener Tweener [get, set]
 The tween manager. More...
 
bool ShowDebugger [get, set]
 True if the debugger is currently open. More...
 
float Framerate [get, set]
 The current framerate of the game. More...
 
float AverageFramerate [get, set]
 The average framerate of the game over the past few seconds. More...
 
float DeltaTime [get, set]
 How much time has passed since the last update. Will only make sense if FixedFramerate is false. More...
 
int Width [get, set]
 The internal width of the game. More...
 
int Height [get, set]
 The internal height of the game. More...
 
int WindowWidth [get, set]
 The window width of the game. More...
 
int WindowHeight [get, set]
 The window height of the game. More...
 
bool WindowFullscreen [get, set]
 If the game window is currently fullscreen. More...
 
Stack< SceneScenes [get, set]
 The stack of scenes currently in the game. More...
 
List< SessionSessions [get, set]
 The list of player sessions currently in the game. More...
 
Input Input [get, set]
 The input used by the game. More...
 
DebugInput DebugInput [get, set]
 The debug input used by the game. More...
 
Surface Surface [get, set]
 The main surface that the game renders to. More...
 
bool IsDebugMode [get, set]
 If the game is currently being run in a Debug Mode build. More...
 
int MouseDeltaX [get, set]
 The change in the mouse's x position before it's relocked to the center. Only reports when LockMouseCenter is set to true. More...
 
int MouseDeltaY [get, set]
 The change in the mouse's y position before it's relocked to the center. Only reports when LockMouseCenter is set to true. More...
 
bool HasFocus [get, set]
 If the window currently has focus. More...
 
DataSaver OptionsData [get, set]
 The stored data for game options. The options file is not externally modifiable. More...
 
DataSaver SaveData [get, set]
 The stored data for the general game data. The file is not externally modifiable. More...
 
DataSaver ConfigData [get, set]
 The stored data for the game config file. The config file is externally modifiable. More...
 
string GameFolder [get, set]
 The default folder to use for storing data files for the game. This will be a folder created in the current user's My Documents folder. The default is 'ottergame' so it will create a folder 'ottergame' in My Documents. More...
 
string Filepath [get]
 The main filepath for saving and loading files for the game. More...
 
float AspectRatio [get, set]
 The aspect ratio of the window that the game is rendering to. More...
 
int Second [get]
 A second in terms of frames for fixed frame rate games. More...
 
List< SurfaceSurfaces [get, set]
 The surfaces that should be rendered to the final game window. Useful for games that need to render to multiple surfaces. More...
 
float CameraAngle [get, set]
 The camera angle for the game's main view. More...
 
float CameraZoom [get, set]
 The camera zoom for the game's main view. More...
 
float RealDeltaTime [get, set]
 The real delta time for each update. More...
 
bool MouseVisible [get, set]
 Set the visibilty of the mouse. More...
 
int RenderTime [get]
 The amount of time in milliseconds for the render pass to complete. More...
 
int UpdateTime [get]
 The amount of time in milliseconds for the update time to complete. More...
 
int RenderCount [get, set]
 The number of draw calls in the last update. More...
 
int UpdateCount [get, set]
 The number of objects that were updated in the last update. More...
 
int HalfWidth [get, set]
 Half of the game's internal width. More...
 
int HalfHeight [get, set]
 Half of the game's internal height. More...
 
Scene Scene [get, set]
 A reference to the current scene being updated by the game. More...
 

Detailed Description

ᶜ(ᵔᴥᵔ)ᵓ Core class Otter. Create a Game, and then use Game.Start(); to run it.

Constructor & Destructor Documentation

Otter.Game.Game ( string  title = "Game",
int  width = 640,
int  height = 480,
int  targetFramerate = 60,
bool  fullscreen = false 
)

Creates a new game to run in the program.

Parameters
titleThe title of the window.
widthThe width of the internal game resolution.
heightThe height of the internal game resolution.
targetFramerateThe target framerate (for fixed framerate.)
fullscreenRun the game in fullscreen.

Member Function Documentation

void Otter.Game.AddScene ( Scene  scene)

Add a scene to the top of the stack. You do not have to use Game.FirstScene if you use this before Game.Start().

Parameters
sceneThe scene to add.
void Otter.Game.AddScene ( params Scene[]  scenes)

Add multiple scenes to the top of the stack. The last scene added will be on top.

Parameters
scenesThe scenes to add.
Session Otter.Game.AddSession ( string  name)

Adds a new Session to the game.

Parameters
nameThe name of the Session.
Returns
The Session.
Session Otter.Game.AddSession ( Enum  name)

Adds a new Session to the game.

Parameters
nameThe name of the Session.
Returns
The Session.
void Otter.Game.AddSurface ( Surface  surface)

Add a surface to the list of surfaces to be rendered to the window.

Parameters
surfaceThe surface to add.
void Otter.Game.CenterWindow ( )

Center the window on the monitor that the window was initialized on.

void Otter.Game.Close ( )

Close the current game window.

void Otter.Game.ForceDebugger ( )

Force the creation of a Debugger object (even in Release mode!)

T Otter.Game.GetScene< T > ( )

Get the current scene cast to a specific type. Useful for when you extend Scene to your own class.

Template Parameters
TThe class to return the scene as.
Returns
The scene as T.
Type Constraints
T :Scene 
void Otter.Game.Pause ( )

Pause the game.

void Otter.Game.PauseToggle ( )

Toggle the pause state on and off.

void Otter.Game.RemoveScene ( )

Remove the scene from the top of the scene stack.

void Otter.Game.RemoveSurface ( Surface  surface)

Remove a surface from the list of surfaces to be rendered to the window.

Parameters
surfaceThe surface to remove.
void Otter.Game.Resume ( )

Resume the game after pausing.

Session Otter.Game.Session ( string  name)

Get a session by the name.

Parameters
nameThe name of the session.
Returns
A session if one is found, or null.
Session Otter.Game.Session ( Enum  name)

Get a Session by the name.

Parameters
nameThe name of the Session.
Returns
A Session if one is found, or null.
Session Otter.Game.Session ( int  id)

Get a session by id.

Parameters
idThe id of the session.
Returns
The Session with that id.
void Otter.Game.SetIcon ( string  source)

Set the icon of the current window.

Parameters
widthThe width of the icon.
heightThe height of the icon.
sourceThe source path to the icon image.
void Otter.Game.SetWindow ( int  width,
int  height = 0,
bool  fullscreen = false,
bool  vsync = false 
)

Creates a new window for the game to be shown in.

Parameters
widthThe width of the window.
heightThe height of the window.
fullscreenRun the window in fullscreen mode.
vsyncEnable vertical sync.
void Otter.Game.SetWindowAutoFullscreen ( bool  vsync = false)

Creates a new window that is the resolution of the screen and in fullscreen mode.

Parameters
vsyncEnable vertical sync.
void Otter.Game.SetWindowScale ( float  scale = 1)

Create a new window using a scale value instead of pixels.

Parameters
scaleThe scale compared to the game's internal resolution.
void Otter.Game.Sleep ( int  milliseconds)

Pauses the game for a certain time. Only works with fixed framerate currently.

Parameters
millisecondsThe time to freeze for in milliseconds.
void Otter.Game.Start ( Scene  firstScene)

Start the game using a specific Scene. Shortcut for setting the FirstScene then using Start.

Parameters
firstSceneThe Scene to begin the game with.
void Otter.Game.Start ( )

Start the game. This will begin the game loop and no other code past Start() in your entry point will run. Make sure to set the first scene before executing this.

void Otter.Game.Stop ( )

Stop the game from running completely.

void Otter.Game.SwitchScene ( Scene  scene)

Switch to a new scene. This removes the scene stack!

Parameters
sceneThe scene to switch to.

Member Data Documentation

bool Otter.Game.Active = false

If the game is currently being run.

bool Otter.Game.AlwaysUpdate = true

If the game should keep updating even when it has lost focus.

Atlas Otter.Game.Atlas = new Atlas()

The default Atlas to search for image assets in.

Color Otter.Game.Color = Color.Black

The default background color of the game.

bool Otter.Game.DrawInactiveScenes = true

If the game should draw all scenes on the stack including inactive scenes.

bool Otter.Game.EnableAltF4 = true

Determines if Alt+F4 will close the game immediately.

bool Otter.Game.EnableQuitButton = true

Determines if the QuitButton can close the game.

Scene Otter.Game.FirstScene

The first scene that the game should load when Start() is called.

bool Otter.Game.FixedFramerate = true

Render and update the game at a fixed framerate. The game will never exceed the target framerate, and will slow down if performance decreases.

int Otter.Game.GameFrames

The number of frames that have passed since the game started. If you're not using fixed framerate then this number will vary wildly.

Game Otter.Game.Instance
static

A reference to the active Game instance.

bool Otter.Game.InvertAngleY = true

Determines if Y values determined by angles in the Util class will invert the Y axis. This is mostly for backwards compatibility. Turn it back to false if you don't want to change all of your math.

Color Otter.Game.LetterBoxColor = Color.Black

The default color to draw in the letterboxed areas of the window.

bool Otter.Game.LockAspectRatio = true

Maintain the original aspect ratio of the game when scaling the window.

bool Otter.Game.LockMouse

If the game should attempt to lock the mouse inside the window. This is not 100% accurate.

bool Otter.Game.LockMouseCenter

If the mouse should be locked to the center of the window. The Input class should still report the mouse position accurately if this is true. This is currently the best way to lock the mouse inside of the window region.

int Otter.Game.LockMousePadding = 10

The distance from the edge of the window in which the mouse cant escape when locked.

bool Otter.Game.MeasureTimeInFrames = true

If the game should measure time in frames when using a fixed framerate. If true delta time will increase by 1 on each update, if false it will increase by 1 / TargetFramerate.

Action Otter.Game.OnEnd = delegate { }

An Action called when the game ends. The last code that executes when closing the game.

Action Otter.Game.OnEndOfUpdate = delegate { }

An action that is called at the very end of the update (the very last thing before Render()) After this is called it will be cleared!

Action Otter.Game.OnFocusGained = delegate { }

An action that is called when the window gains focus.

Action Otter.Game.OnFocusLost = delegate { }

An action that is called when the window loses focus.

Action Otter.Game.OnInit = delegate { }

An action called when the game initializes.

Action Otter.Game.OnSceneBegin = delegate { }

An action called when any Scene begins.

Action Otter.Game.OnSceneEnd = delegate { }

An action called when any Scene ends.

Action Otter.Game.OnStartOfNextUpdate = delegate { }

An action that is called at the very start of the next update (the very first thing before UpdateFirst()) After this is called it will be cleared!

Action Otter.Game.OnUpdate = delegate { }

An action called when the game updates (happens after all Scene and Entity updates.)

bool Otter.Game.Paused = false

If the game is paused (no longer updating.)

Button Otter.Game.QuitButton = new Button()

Button that closes the game when pressed. Defaults to the Escape key.

bool Otter.Game.ReleaseModeDebugger = false

Determines if the debug console will be available when building in release mode. Must be set before Game.Start() is called.

Button Otter.Game.ScreenshotButton = new Button()

Button that will save the game's surface out to a timestamp named .png file after the next render.

int Otter.Game.TargetFramerate

The desired framerate that the game should update at.

float Otter.Game.Timer

How long the game has been active. Measured in units of delta time.

string Otter.Game.Title

The title of the game displayed in the window.

bool Otter.Game.WindowBorder = true

Determines if the game window has a border. If the window has no border it cannot be resized or closed with the close button or Alt+F4. Must be set before calling Game.SetWindow() or Game.Start()

bool Otter.Game.WindowClose = true

Determines if the game window has a close button or Alt+F4. Must be set before calling Game.SetWindow() or Game.Start().

bool Otter.Game.WindowResize = true

Determines if the game window can be resized. Must be set before calling Game.SetWindow() or Game.Start().

Property Documentation

float Otter.Game.AspectRatio
getset

The aspect ratio of the window that the game is rendering to.

float Otter.Game.AverageFramerate
getset

The average framerate of the game over the past few seconds.

float Otter.Game.CameraAngle
getset

The camera angle for the game's main view.

float Otter.Game.CameraZoom
getset

The camera zoom for the game's main view.

DataSaver Otter.Game.ConfigData
getset

The stored data for the game config file. The config file is externally modifiable.

Coroutine Otter.Game.Coroutine
getset

The Coroutine manager.

Debugger Otter.Game.Debugger
getset

The debugger. Only accessable in Debug mode, otherwise null.

DebugInput Otter.Game.DebugInput
getset

The debug input used by the game.

float Otter.Game.DeltaTime
getset

How much time has passed since the last update. Will only make sense if FixedFramerate is false.

string Otter.Game.Filepath
get

The main filepath for saving and loading files for the game.

float Otter.Game.Framerate
getset

The current framerate of the game.

string Otter.Game.GameFolder
getset

The default folder to use for storing data files for the game. This will be a folder created in the current user's My Documents folder. The default is 'ottergame' so it will create a folder 'ottergame' in My Documents.

int Otter.Game.HalfHeight
getset

Half of the game's internal height.

int Otter.Game.HalfWidth
getset

Half of the game's internal width.

bool Otter.Game.HasFocus
getset

If the window currently has focus.

int Otter.Game.Height
getset

The internal height of the game.

Input Otter.Game.Input
getset

The input used by the game.

bool Otter.Game.IsDebugMode
getset

If the game is currently being run in a Debug Mode build.

int Otter.Game.MouseDeltaX
getset

The change in the mouse's x position before it's relocked to the center. Only reports when LockMouseCenter is set to true.

int Otter.Game.MouseDeltaY
getset

The change in the mouse's y position before it's relocked to the center. Only reports when LockMouseCenter is set to true.

bool Otter.Game.MouseVisible
getset

Set the visibilty of the mouse.

DataSaver Otter.Game.OptionsData
getset

The stored data for game options. The options file is not externally modifiable.

float Otter.Game.RealDeltaTime
getset

The real delta time for each update.

int Otter.Game.RenderCount
getset

The number of draw calls in the last update.

int Otter.Game.RenderTime
get

The amount of time in milliseconds for the render pass to complete.

DataSaver Otter.Game.SaveData
getset

The stored data for the general game data. The file is not externally modifiable.

Scene Otter.Game.Scene
getset

A reference to the current scene being updated by the game.

Stack<Scene> Otter.Game.Scenes
getset

The stack of scenes currently in the game.

int Otter.Game.Second
get

A second in terms of frames for fixed frame rate games.

List<Session> Otter.Game.Sessions
getset

The list of player sessions currently in the game.

bool Otter.Game.ShowDebugger
getset

True if the debugger is currently open.

Surface Otter.Game.Surface
getset

The main surface that the game renders to.

List<Surface> Otter.Game.Surfaces
getset

The surfaces that should be rendered to the final game window. Useful for games that need to render to multiple surfaces.

Tweener Otter.Game.Tweener
getset

The tween manager.

int Otter.Game.UpdateCount
getset

The number of objects that were updated in the last update.

int Otter.Game.UpdateTime
get

The amount of time in milliseconds for the update time to complete.

int Otter.Game.Width
getset

The internal width of the game.

bool Otter.Game.WindowFullscreen
getset

If the game window is currently fullscreen.

int Otter.Game.WindowHeight
getset

The window height of the game.

int Otter.Game.WindowWidth
getset

The window width of the game.

int Otter.Game.WindowX
getset

Set the X position of the Window.

int Otter.Game.WindowY
getset

Set the Y position of the Window.


The documentation for this class was generated from the following file: