Actionable Input!
timbeaudet
[cpp]
class InputAction
{
public:
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);
private:
KeyContainer mKeyBindings;
};
[/cpp]
Just before LudumDare 36 I added a new way to handle input to TurtleBrains framework, it is quite simple but so far I really enjoy the way it is used. It is just a powerful little object that can
check the input manager for each of the bound keys allowing an action to bound to:
- Any key (supported by framework)
- Multiple keys at once!
- No keys at all!
The second one is quite interesting, consider implementing a splash or title screen with multiple ways to continue into game. Without the input action, it required multiple checks, and more lengthy code.
[cpp]
{
//Old way of performing input check
if (true == Input::IsPressed(KeyEscape) ||
true == Input::IsPressed(KeySpace) ||
true == Input::IsPressed(KeyEnter))
{
//Goto gameplay scene.
}
//New way with InputAction:
if (true == mSkipForward.IsPressed())
{
//Goto gameplay scene.
}
}
[/cpp]
Of course to a slight degree this is just moving the code from the update area to initialization:
[cpp]
{
mSkipForward.AddBinding(KeyEscape);
mSkipForward.AddBinding(KeySpace);
mSkipForward.AddBinding(KeyEnter);
}
[/cpp]
But considering it could allow use WASD and arrows keys for movement, or, _with a binding screen_ the user could configure controls to their own liking. This is the first pass I make over such a system and so far I’ve enjoyed the usage better than the previous methods.