Skip to content

Commit 69a3ad2

Browse files
committed
Add helper method for combined positive/negative inputs to InputManager
1 parent 390d949 commit 69a3ad2

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

arcade/input/manager.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,26 @@ def add_axis_input(self, axis: str, input: InputEnum, scale: float = 1.0):
427427
self.controller_analog_to_axes[input.value] = set()
428428
self.controller_analog_to_axes[input.value].add(axis)
429429

430+
def add_axis_input_combined(self, axis: str, positive: InputEnum, negative: InputEnum, scale: float = 1.0):
431+
"""
432+
This is a helper function that wraps :meth:`arcade.InputManager.add_axis_input` to add two inputs
433+
with a positive and negative scale.
434+
435+
For example, you can do:
436+
add_axis_input_combined("MoveHorizontal", arcade.Keys.RIGHT, arcade.Keys.LEFT, 1.0)
437+
instead of:
438+
add_axis_input("MoveHorizontal", arcade.Keys.RIGHT, 1.0)
439+
add_axis_input("MoveHorizontal", arcade.Keys.LEFT, -1.0)
440+
441+
Args:
442+
axis: The axis name to register the input for
443+
positive: The input that will correspond to the positive side of the axis
444+
negative: The input that will correspond to the negative side of the axis
445+
scale: The value to multiply the input by, for non analog inputs the scale value is used literally.
446+
"""
447+
self.add_axis_input(axis, positive, scale)
448+
self.add_axis_input(axis, negative, -scale)
449+
430450
def clear_axis_input(self, axis: str):
431451
self.axes[axis]._mappings.clear()
432452
_clean_dicts(

0 commit comments

Comments
 (0)