TurtleBrains  0.3.1
High quality, portable, C++ framework for rapid 2D game development.
TurtleBrains::Game::InputAction Class Reference

#include <tb_input_action.h>

Public Member Functions

 InputAction (void)
 
 InputAction (const tbApplication::Key &keyBinding)
 
 ~InputAction (void)
 
bool IsDown (void) const
 
bool IsPressed (void) const
 
bool IsReleased (void) const
 
void ClearBindings (void)
 
void AddBinding (const tbApplication::Key &keyBinding)
 
void RemoveBinding (const tbApplication::Key &keyBinding)
 

Static Public Member Functions

static void UpdateActionOnSimulate (bool onSimulateStep=true)
 

Detailed Description

An object to manage watching one-many keys to perform game actions and hide details about the bound keys from code using the action.

Constructor & Destructor Documentation

TurtleBrains::Game::InputAction::InputAction ( void  )

Constructs an InputAction that contains no bindings.

TurtleBrains::Game::InputAction::InputAction ( const tbApplication::Key keyBinding)
explicit

Constructs an InputAction that binds to the Key given.

Parameters
keyBindingThe Key to bind to the InputAction object during construction.
TurtleBrains::Game::InputAction::~InputAction ( void  )

Destroys the InputAction object.

Member Function Documentation

void TurtleBrains::Game::InputAction::AddBinding ( const tbApplication::Key keyBinding)

Adds a Key binding to the InputAction so that it will get tracked for Down, Pressed or Released events.

Parameters
keyBindingThe Key to bind to the InputAction.
void TurtleBrains::Game::InputAction::ClearBindings ( void  )

Removes ALL bindings from the input action so there are no keys or inputs that will trigger any of the Down, Pressed or Release events.

bool TurtleBrains::Game::InputAction::IsDown ( void  ) const

This will check each of the Keys bound to the InputAction to see if ANY of the keys that are bound to the InputAction is Down at the moment, returning true if that is the case.

bool TurtleBrains::Game::InputAction::IsPressed ( void  ) const

This will check each of the Keys bound to the InputAction to see if ANY of the keys that are bound to the InputAction is Pressed at the moment, returning true if that is the case.

Note
This is probably not the expected or desired result and behavior will likely change in the future to ensure that the InputAction as a whole acts like a single button, regardless of the different Key bindings. If an InputAction has 'A' and 'B' bound, and 'A' is held down, pressing 'B' will (as implemented now) cause IsPressed() to return true. This is likely a rare edge case.
bool TurtleBrains::Game::InputAction::IsReleased ( void  ) const

This will check each of the Keys bound to the InputAction to see if ANY of the keys that are bound to the InputAction is Pressed at the moment, returning true if that is the case.

Note
This is probably not the expected or desired result and behavior will likely change in the future to ensure that the InputAction as a whole acts like a single button, regardless of the different Key bindings. If an InputAction has 'A' and 'B' bound, and 'A' is held down, pressing 'B' will (as implemented now) cause IsPressed() to return true. This is likely a rare edge case.
void TurtleBrains::Game::InputAction::RemoveBinding ( const tbApplication::Key keyBinding)

Removes a specific Key from the InputAction while keeping any other Keys as they were.

Parameters
keyBindingThe Key binding to remove from the InputAction.
static void TurtleBrains::Game::InputAction::UpdateActionOnSimulate ( bool  onSimulateStep = true)
static

This will change when ALL InputAction objects update the status of their Keys from or to the SimulateStep or the UpdateStep portion of the frame.

Parameters
onSimulateStepshould be true to poll input during each of the 0-N Simulate steps during a frame or false to poll during the Update step.
Note
Since Simulate can run 0 times, it IS possible, though really unlikely, that a press/release is skipped if the framerate, and player, is fast enough to press/release with 2 frames of 0 Simulate steps.