Node-like Event emitter for easily usage.
On:
update
connected
disconnected
buttonUpdate
, (name:string
, value:number
, index:number
) =>void
):XPad
buttonPressed
, (name:string
, index:number
) =>void
):XPad
buttonReleased
, (name:string
, index:number
) =>void
):XPad
joysticksUpdate
, (joysticks:Joysticks
, index:number
) =>void
):XPad
leftJoystickUpdate
, (joystick:Joystick
, index:number
) =>void
):XPad
rightJoystickUpdate
, (joystick:Joystick
, index:number
) =>void
):XPad
For more detail, please read this file
<body>
<script src="xPad.js"></script>
<script>
xPad.once("connected", () => {
console.log("Connected!")
})
xPad.on("buttonUpdate", console.log)
</script>
</body>
0 \ 1 (boolean) |
0...1 (tension) |
---|---|
A, B, X, Y, LB, RB, BACK, START, L-STICK, R-STICK, UP, DOWN, LEFT, RIGHT | LT, RT |
// get props on your own game loop
const LT_Value = xPad.buttons["LT"]
const LT_IsPressed = LT_Value === 1
const UP_IsPressed = !!xPad.buttons.UP
// or use events
xPad.on("buttonPressed", name => {
if(name === "A") player.jump()
})
interface Joysticks {
left: Joystick
right: Joystick
}
interface Joystick {
x: number
y: number
}
{
"left": {"x": 0, "y": 0},
"right": {"x": 0, "y": 0}
}
xPad.on("rightJoystickUpdate", joystick => {
["x","y"].forEach(a => {
player.position[a] += joystick[a] * player.speed[a]
})
})
xPad.on("leftJoystickUpdate", joystick => {
["x","y"].forEach(a => {
player.pointer[a] += joystick[a] * player.sensitivity[a]
})
})
Change the speed of gamepad checking (update event).