Skip to content

Game class reference

Alan Stagner edited this page Jun 9, 2020 · 2 revisions

Virtual Methods

virtual void Initialize() - Initialize your game here


virtual void LoadContent() - Load your game's content upfront here (you can load it at any time after this, but if you need to load anything upfront here is a good place to do it!) Will be called after Initialize.


virtual void UnloadContent() - Unload any content you've loaded into memory here.


virtual void Teardown() - Do any final teardown here. This will be called after UnloadContent.


virtual void Update(GameTime time) - Update game logic here


virtual void Draw(GameTime time) - Perform rendering logic here

Methods

void Run() - Start the game running


void Exit() - Stop the game & exit

Properties

GameWindow Window { get; } - Get the current game window. You can use this to do things like listen for certain window events, check the location and size of the game window, the display orientation, set the window title, etc.


GraphicsDevice GraphicsDevice { get; } - Get the graphics device. You can use this to submit rendering commands (clear the current target, submit geometry buffers, etc)


SpriteBatch SpriteBatch { get; } - Get the SpriteBatch instance. You can use this as a quick & simple way to draw 2D sprites.


Audio Audio { get; } - Get the Audio instance. Use this to play music & sound effects


Keyboard Keyboard { get; } - Get the Keyboard instance. Use this to query keyboard keys & listen for keyboard events


Mouse Mouse { get; } - Get the Mouse instance. Use this to query mouse position, scroll wheel, mouse button, & listen for mouse events


GamepadCollection Gamepads { get; } - Get the collection of all gamepads currently connected. Each gamepad can be queried for thumbsticks, triggers, buttons, & gamepad events


Event<GamepadAddedHandler> OnGamepadAdded - Event triggered when a new gamepad is added


Event<GamepadRemovedHandler> OnGamepadRemoved - Event triggered when a gamepad is disconnected