Remarks
Pollsnavigator.getGamepads() once per frame and exposes a snapshot of
every connected controller on Context.controller. Buttons and axes follow
the W3C “standard” layout (ControllerButton, ControllerAxis); every
method takes an optional controller index, 0 by default. Client-only —
__init throws if the Gamepad API is unavailable. Browsers only expose a
controller after the user pressed one of its buttons.
Example
Extends
Library
Constructors
Constructor
new ControllerLibrary(Defined in: modules/input/src/controller/controller.library.ts:43options?):ControllerLibrary
Parameters
options?
ControllerLibraryOptions = {}
Returns
ControllerLibrary
Overrides
Library.constructor
Properties
key
Defined in: modules/input/src/controller/controller.library.ts:38 This library’s identity: its slot onreadonlykey:"controller"
Context, its registry key, and
the identifier used to reference it in ordering relationships.
Overrides
Library.key
Accessors
relationships
Get Signature
get relationships(): LibraryRelationships
Defined in: packages/common/dist/index.d.ts:512
Internal
Returns
LibraryRelationships
Inherited from
Library.relationships
Methods
__clear()
__clear():Defined in: modules/input/src/controller/controller.library.ts:64 Called once after the tick loop stops.Promise<void>
Returns
Promise<void>
Overrides
Library.__clear
__events()
__events(Defined in: packages/common/dist/index.d.ts:521 Called every tick, in run order, whether or not the tick loop is paused — unlike_ctx):Promise<void>
__run. Use this for event/message draining that must
not be affected by pause (e.g. listening for the command that resumes
the loop), not for gameplay simulation.
Parameters
_ctx
Context
Returns
Promise<void>
Inherited from
Library.__events
__init()
__init():Defined in: modules/input/src/controller/controller.library.ts:52 Called once, in dependency order, before the tick loop starts.Promise<void>
Returns
Promise<void>
Overrides
Library.__init
__run()
__run():Defined in: modules/input/src/controller/controller.library.ts:59 Called every tick, in run order, while the tick loop is active and not paused.Promise<void>
Returns
Promise<void>
Overrides
Library.__run
expose()
expose(): ControllerContextApi
Defined in: modules/input/src/controller/controller.library.ts:143
Returns this library’s public contribution to Context[this.key].
Returns
ControllerContextApi
Remarks
Return a plain object exposing only what game code should be able to reach — neverthis — so internal state and lifecycle hooks never leak
onto Context. Libraries with nothing to expose (headless libraries)
can leave this unimplemented; they simply won’t appear on Context.
Overrides
Library.expose
getAxis()
getAxis(Defined in: modules/input/src/controller/controller.library.ts:104axis,index?):number
Parameters
axis
ControllerAxis
index?
number = 0
Returns
number
The axis value between -1 and 1, with the deadzone applied.
getButtonValue()
getButtonValue(Defined in: modules/input/src/controller/controller.library.ts:98button,index?):number
Parameters
button
ControllerButton
index?
number = 0
Returns
number
The analog value of the button, between 0 and 1.
getController()
getController(Defined in: modules/input/src/controller/controller.library.ts:73index?):ControllerState|undefined
Parameters
index?
number = 0
Returns
ControllerState | undefined
getControllers()
getControllers(): ControllerState[]
Defined in: modules/input/src/controller/controller.library.ts:68
Returns
ControllerState[]
getStick()
getStick(Defined in: modules/input/src/controller/controller.library.ts:110stick,index?):StickPosition
Parameters
stick
ControllerStick
index?
number = 0
Returns
StickPosition
The stick position, with a radial deadzone applied.
isButtonJustPressed()
isButtonJustPressed(Defined in: modules/input/src/controller/controller.library.ts:87button,index?):boolean
Parameters
button
ControllerButton
index?
number = 0
Returns
boolean
isButtonJustReleased()
isButtonJustReleased(Defined in: modules/input/src/controller/controller.library.ts:92button,index?):boolean
Parameters
button
ControllerButton
index?
number = 0
Returns
boolean
isButtonPressed()
isButtonPressed(Defined in: modules/input/src/controller/controller.library.ts:82button,index?):boolean
Parameters
button
ControllerButton
index?
number = 0
Returns
boolean
isConnected()
isConnected(Defined in: modules/input/src/controller/controller.library.ts:78index?):boolean
Parameters
index?
number = 0
Returns
boolean
onConnect()
onConnect(Defined in: modules/input/src/controller/controller.library.ts:132listener): () =>void
Parameters
listener
ControllerListener
Returns
A function that removes the listener. () =>void
onDisconnect()
onDisconnect(Defined in: modules/input/src/controller/controller.library.ts:138listener): () =>void
Parameters
listener
ControllerListener
Returns
A function that removes the listener. () =>void
throwNotInitializedError()
Defined in: packages/common/dist/index.d.ts:536protectedthrowNotInitializedError():never
Returns
never
Inherited from
Library.throwNotInitializedError
vibrate()
vibrate(Defined in: modules/input/src/controller/controller.library.ts:121 Plays a rumble effect.effect,index?):Promise<boolean>
Parameters
effect
ControllerVibration
index?
number = 0
Returns
Promise<boolean>
true if the effect played to completion, false if the
controller has no vibration support or the effect was interrupted.