Skip to content

Analog Stick Events

jackcarey edited this page Jul 16, 2022 · 1 revision
Event Fires when…
gc.analog.start …an analog stick moves from center.
gc.analog.hold …an analog stick is away from center. Fires continuously until the analog stick returns to center.
gc.analog.change …an analog stick's position changes. Similar to gc.analog.hold, but does not fire when the stick is away from center but the position hasn't changed.
gc.analog.end …an analog stick returns to center.

These events pass an AnalogStick instance to the detail property of the Event object.

Example

window.addEventListener('gc.analog.hold', function(event) {
	console.log(event.detail);
}, false);

>> AnalogStick {}

Events

gc.analog.start

This is fired as when an analog stick leaves it's center position.

gc.analog.hold

This event fires rapidly as long as an analog stick is not at it's center positon. The interval at which it fires is tied to requestAnimationFrame() and therefor cannot be guaranteed to be regular.

gc.analog.change

This event fires any time the analog stick's position has changed since the last update. It is similar to gc.analog.hold with the main difference being that it does not fire while the stick is held still in a single location.

gc.analog.end

This is fired when an analog stick returns to it's center postion.

AnalogStick Objects

An AnalogStick object represents an analog stick input's state.

Properties

Name Type Description
controllerIndex Int The [[index
time Int A DOMHighResTimeStamp representing when the analog stick was updated.
name String The name of the analog stick.
position.x Float A number between -1 (left) and 1 (right), indicating the x-axis position of the analog stick.
position.y Float A number between -1 (up) and 1 (down), indicating the y-axis position of the analog stick.
angle.degrees Float/NaN A number between 0 and 360 indicating the angle in degrees the analog stick is pressed, or NaN if the stick is at origin.
angle.radians Float/NaN A number between 0 and ~6.283 ( 2π ) indicating the angle in radians the analog stick is pressed, or NaN if the stick is at origin.

Be aware that the recommended method of checking whether a value is NaN is to use the isNaN() function.

Example

// AnalogStick object
AnalogStick {
	controllerIndex: 0,
	time: 4526.165,
	name: "LEFT_ANALOG_STICK",
	position: { x: 0, y: 0 },
	angle: { degrees: NaN, radians: NaN }
}
Clone this wiki locally