-
Notifications
You must be signed in to change notification settings - Fork 1
Input Handling
Jump To | back |
Overview | Contents | Macros |
---|
The Input Handling module is concerned with combining and consolidating inputs. It provides an interface for generic input types, a generic input device, as well as wrappers for gamepad, mouse and keyboard inputs. Lastly, it can automatically handle connection and disconnection of gamepads.
Dependencies: Core
InputDevices are generic containers for control mappings. Rather than polling the keyboard or gamepad directly, you can simply name your inputs whatever you wish and then assign the inputs you want to them. Here is an example of a simple, two-input controller:
global.controller = new InputDevice( "shoot", "jump" );
global.controller.shoot.bind( new KeyboardKey( vk_control ) );
global.controller.jump.bind( new KeyboardKey( vk_space ) );
We can now check the status of our inputs:
if ( global.controller.shoot.pressed() ) {}
InputDevices support the following checks: pressed()
, held()
and released()
.
NOTE: When
pressed()
,held()
orreleased()
is called, the initial state of the button will be set. This means that callingpressed()
orheld()
multiple times in the same frame could yield unexpected results. If you require checking the same button multiple times in a single frame, it is recommended to cache the initial query, or create multiple InputDevices.
Gamepads are a little like input devices except they have to be created before they can be used:
global.gamepad = new GamepadXbox();
It is then possible to poll the controls on it the same as you would an InputDevice. However, gamepad inputs can also be fed into InputDevices to combine them with other types of inputs:
global.controller.shoot.bind( global.gamepad.a, new KeyboardKey( vk_space ) );
In this case we bind the A button on our gamepad and the spacebar to our shoot control. Gamepads are automatically managed, connections and disconnections are handled without further input from the user.
Name | Type | Value | Description |
---|---|---|---|
GAMEPAD_MAXIMUM_VIRTUAL_PORTS | int | 4 | The number of virtual ports gamepads can plug into |
Devon Mullane 2020