-
Notifications
You must be signed in to change notification settings - Fork 1
Buttons and Analog Sticks
Buttons and Analog Sticks both have a set of events used to report different kinds of changes in those inputs' states.
Each input event will have the corresponding input object made available through the details
attribute of the Event
object.
// Button press event
window.addEventListener('gc.button.press', function(event) {
var button = event.detail;
console.log(button);
}, false);
>> Button {
>> controllerIndex: 0,
>> time: 4526.165,
>> name: "DPAD_UP",
>> pressed: true,
>> value: 1
>> }
→ All Button Events
→ [[Details about Button
objects|Button Events#button-objects]]
// Analog Stick start movement event
window.addEventListener('gc.analog.start', function(event) {
var stick = event.detail;
console.log(stick);
}
>> AnalogStick {
>> controllerIndex: 0,
>> time: 4526.165,
>> name: "LEFT_ANALOG_STICK",
>> position: { x: -0.3102, y: 0 },
>> angle: { degrees: 180, radians: 3.142 }
>> }
→ All Analog Stick Events
→ [[Details about AnalogStick
objects|Analog Stick Events#analogstick-objects]]
In the case that you have multiple controllers connected, and for a period of time you want to ignore all events fired from one of them, you can use the .watch()
and .unwatch()
methods.
var controller = Controller.getController(0);
controller.unwatch();
// No button or analog stick events will fire for this controller
controller.watch();
// Events will resume firing for this controller
The Controller
object also has .watchAll()
and unwatchAll()
methods for ignoring and resuming events from all controllers.
The MIT License (MIT)
Copyright © 2022 Jack Carey
Setup
Buttons & Analog Sticks
Controller Layouts
Configuring Settings
Controller Events
Button Events
Analog Stick Events
Controller.supported
Controller.controllers
Controller.controllerCount
Controller.search()
Controller.getController()
Controller.watchAll()
Controller.unwatchAll()
.connectedTimestamp
.id
.index
.inputs
.layoutInfo
.name
.watch()
.unwatch()
Settings Objects
List of Settings
settings.list()
settings.clear()
settings.update()
→ Grunt Tasks
→ Registering Settings
→ Creating Layout Maps