Skip to main content

Inputs

What makes your game a game is that the players can control the outcome. They do this using inputs. Easel supports multiple input methods, including the mouse, keyboard, touchscreens and gamepads. You can also simulate input (normally used for bot players), and remap controls. This page gives you an overview of all of these topics.

Button presses

The ButtonDown, ButtonUp and IsButtonDown functions signal when a particular button is pressed by a particular player. Buttons can be keyboard keys, mouse buttons, gamepad buttons or touchscreen taps. See Keycodes for a full list of all possible buttons that can be pressed.

Remapping

The KeyRebindingBlock user interface element allows a player to remap keys. When they select the elemet, the player can choose a new key they would like to press instead of the original key.

Pointers

Normally a pointer refers to a mouse.

  • The Pointer prop contains the last position of a player's mouse pointer.
  • The IsPointerActive property will be true if the mouse is within the boundaries of the game window, and false otherwise.

Touchscreens

The TouchscreenMode function can be used to determine whether a player is using a touchscreen device. Sometimes the value will be undefined initially as it requires waiting the user to use their mouse or touch the screen before it can be determined. You can await TouchscreenMode to watch for any changes to this property.

Clicks vs Taps

The Click keycode specifically refers to a click from a mouse, whereas Tap keycode specifically only handles taps to a touchscreen. This allows you to distinguish the two forms of input.

If your codebase only refers to Click and never Tap, a Tap will be auto-remapped to Click (same as doing ButtonRemap(Tap, Click)). The same applies vice versa - i.e. there will be an implicit ButtonRemap(Click, Tap) if Click is never used.

Touchscreen only UI elements

The TouchscreenOnly/NonTouchscreenOnly UI layout elements let you show elements of the UI only to either touchscreen or non-touchscreen users. This allows you to display relevant instructions to that player's input device, for example telling the player to "tap" if they are on a touchscreen but "click" if they are not.

Gamepads

The IsGamepadConnected function can be used to determine whether a gamepad is connected. Gamepad may not be supported on all devices and all platforms. Currently Google Chrome has the best support for gamepads. Gamepads may also have differing layouts and capabilities.

Gamepads can have up to two joysticks, these can be read using the Joystick and Joystick2 functions. The VirtualJoystick and VirtualJoystick2 functions allow you to create a simulated on-screen joystick for mouse or touchscreen users. The KeyboardVirtualJoystick function allows you to map keyboard keys to a virtual joystick. This can be used to support common control schemes like WASD or Arrow keys in a unified manner.

Simulating input

A common method for implementing bot players is to simulate input. This can be done by simply calling the same functions that are used to signal input from a real player. Pointers can be simulated by assigning to the Pointer or IsPointerActive props. Button presses can be simulated by calling ButtonDown or ButtonUp. Joystick movements can be simulated by setting the Joystick or Joystick2 props.

Unifying Inputs

To support multiple input methods, you should nominate one input method as the canonical input method for your game, and then remap all other input methods to the canonical input method. See Unification for more information.