Input - NocturnalWisp/Tynted-Engine GitHub Wiki
Input is what makes a game, a game. So obviously you are going to need it. The engine wraps up the SFML input system to make it convenient. This involves two classes:
- InputManager - Creates and accesses input.
- KeyBinding - The binding behind the manager that controls a specific input type.
Do note that this system allows you to change key bindings at run-time and easily remap them.
The input system is helpful to mapping an array of keys, buttons, and even joystick controls to one mapping. This is how you would use it in the initialize :
InputManager.AddBinding(new KeyBinding(mapName,
new List<Keys>() { Keys.Up },
new List<Button>() {},
//Gamepad buttons are determined by a uint.
new List<uint>() { 0 })
);To actually use an input mapping, you often poll for it in the update method. There are two main options for checking input:
- IsDown - If the mapping currently is being pressed.
- JustPressed - If the mapping was just pressed in the last frame.
An example of JustPressed is shown here:
if (InputManager.GetBinding(mapName).JustPressed)
{
//Do something.
}Use the RemoveBinding method to attain this:
InputManager.RemoveBinding(mappingName);Input is a big part of games, and this class will help you to quickly accept input from the user.