gamepad support

This commit is contained in:
Tomáš Mládek 2021-04-08 20:54:59 +02:00
parent c104a70dbe
commit 9003761097

View file

@ -319,6 +319,8 @@ export default defineComponent({
mousePosition.y = (mouse.clientY - transform.y) / currentRatio;
});
let gamePadZoomSpeed = 10;
function animate() {
if (stats) {
stats.begin();
@ -374,6 +376,38 @@ export default defineComponent({
}
}
if (navigator.getGamepads) {
var gamepads = navigator.getGamepads();
var gp = gamepads[0];
if (gp) {
if (gp.buttons[7].pressed) {
gamePadZoomSpeed += .1;
}
if (gp.buttons[5].pressed) {
gamePadZoomSpeed -= .1;
}
if (gamePadZoomSpeed < 1) {
gamePadZoomSpeed = 1;
}
if (gamePadZoomSpeed > 30) {
gamePadZoomSpeed = 30;
}
const transform = pz.getTransform();
const horizontalShift = gp.axes[0] * -1 * gamePadZoomSpeed;
const verticalShift = gp.axes[1] * -1 * gamePadZoomSpeed;
if (horizontalShift || verticalShift) {
pz.moveTo(
transform!.x + horizontalShift,
transform!.y + verticalShift
);
}
}
}
if (stats) {
stats.end();
}