Download presentation
Presentation is loading. Please wait.
Published byShinta Halim Modified over 5 years ago
1
05 | Capturing User Input Michael “Mickey” MacDonald | Indie Game Developer Bryan Griffiths | Software Engineer/Game Developer
2
Module Overview Aggregating Input From Multiple Sources
Capturing User Input Applying The Input
3
Aggregating Input From Multiple Sources
What we want to support Keyboard Input Mouse Input Gamepad Input Touch Input Start by creating a single class to listen for the input events and combine all of these input sources into one responsive entity. Add helper functions allowing the rest of the game to access the bits and pieces of input that they are concerned with.
4
Capturing User Input Input is delivered in the form of events.
Event handlers listen for a given event and then call a function that you associated with that event handler. void MoveLookController::Initialize(_In_ CoreWindow^ window ) { window->KeyDown += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &MoveLookController::OnKeyDown); window->KeyUp += ref new TypedEventHandler<CoreWindow^, KeyEventArgs^>(this, &MoveLookController::OnKeyUp); } Note: You can unsubscribe an event handler using -=
5
Capturing User Input So now that we are listening for an event what does the receiving function need to look like to handle the event? void MoveLookController::OnKeyDown( _In_ CoreWindow^, _In_ KeyEventArgs^ args ) { Windows::System::VirtualKey Key; Key = args->VirtualKey; // Figure out the command from the keyboard. if (Key == VirtualKey::W) m_forward = true; }
6
Capturing User Input So the basic process for capturing player input is: Register an event handler and associated callback. Write the callback to accept the sender and argument parameters. Determine what the actual key/button/movement was for that event and set an internal variable accordingly. The other argument types that we will need are: PointerEventArgs MouseEventArgs
7
Capturing User Input Controller Input
We need to use a polling system to check for input. This will take place during our Update stage on a call from the main game loop each frame. We use DirectX 11’s XInput API for access to the controllers attached to the system at any given time. (Even a Dance Pad!) Main Game Loop’s Update -> Controller’s Update -> Polls the gamepad.
8
Checking out the differences between event handlers and the gamepad polling systems.
9
Applying The Input Do not apply the input as you receive it from a given source. Set up booleans and/or states to handle when one of the sources has activated a given action. Then deal with those actions during the Update function of your controller class. This way multiple control systems can’t be used to cheat by doubling the input and you won’t have to check for as many of those scenarios.
10
Taking a look at how we apply the input from each source and testing that it does in fact work.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.