GameInput
Class that contains all information about the current input during a given frame from the remote
Properties
button(string) — The name of the button associated with the current inputbuttonCode(integer) — The code for the inputpress(boolean) — Was the button pressed since the last frameheld(boolean) — Was the button held down since last framerelease(boolean) — Was the button released this frameheldTimeMs(integer) — How many milliseconds was the current input held forplayerIndex(integer) — Which controller this input came from - -1 for the physical remote, ' 0+ for a connected browser controller (see BGE.Controller.ControlMap).consumed(boolean) — Set by a UiWidget/UiContainer that acted on this event - once set, the ' owning UiContainer stops this event from also reaching GameEntity.onInput() ' for the rest of this frame (see Game.setInputEntity()).x(float) — Current horizontal directional input: left -> -1, right -> 1y(float) — Current vertical directional input, in world space (+y is up, matching ' the engine's world coordinate convention - the renderer flips this when ' projecting to raster/canvas space): up -> 1, down -> -1
Example
' -------Button Code Reference--------
' Button Pressed Released Held
' ------------------------------
' Back 0 100 1000
' Up 2 102 1002
' Down 3 103 1003
' Left 4 104 1004
' Right 5 105 1005
' OK 6 106 1006
' Replay 7 107 1007
' Rewind 8 108 1008
' FastForward 9 109 1009
' Options 10 110 1010
' Play 13 113 1013Constructor
new GameInput(
buttonCode: integer,
heldTimeMs: integer,
playerIndex?: integer,
explicitButtonName?: string,
): GameInputCreates a GameInput object based on the buttonCode. A controller-originated event passes playerIndex/explicitButtonName - see BGE.Controller.ControlMap, which is the normal way to consume controller input rather than constructing this directly.
Parameters
buttonCode(integer) — button to use for the dataheldTimeMs(integer) — how long was this button held forplayerIndex(integer, optional, default: -1) — 1 for the remote, 0+ for a controllerexplicitButtonName(string, optional, default: "invalid") — overrides buttonNameFromCode, used for controller buttons
Instance Methods
isButton(buttonName: string): boolean
Is this input for the given button name? Accepts common aliases in addition to BGE's own button names (case insensitive) - e.g. "select"/"info"/"ff"/"rewind" all resolve to the same buttons as "ok"/"options"/"fastforward"/"rewind". See BGE.buttonAliasToName() for the full alias list.
Parameters
buttonName(string) — the button name (or alias) to check
Returns
boolean
isDirectionalArrow(): boolean
Is this input from the directional pad
Returns
boolean
consume(): void
Marks this input as handled by a UI widget, so it won't also reach regular GameEntity.onInput() callbacks this frame.
Returns
void