// y will still be in range (-0.5, 0.5), but the range for x will be smaller or larger.
let x = (viewportLocalX - bbox.x - (bbox.width / 2)) / bbox.height;
let y = (viewportLocalY - bbox.y - (bbox.height / 2)) / bbox.height;
+ if(game.settings['controls'] == 'touchpad') {
+ sensorElem.children[0].style.left = ((0.5 + x) * 100) + '%';
+ sensorElem.children[0].style.top = ((0.5 + y) * 100) + '%';
+ }
if(game.settings['controls'] == 'touchpad') {
x *= 1.05;
y *= 1.05;
document.body.addEventListener('mousemove', e => cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1)));
document.body.addEventListener('mousedown', e => {
- if(game.settings['controls'] == 'thumbstick') {
- if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
+ if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
+ if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput || game.settings['controls'] == 'touchpad') {
game.ui.virtualInput.inProgress = true;
+ game.ui.virtualInput.children[0].style.display = 'block';
e.preventDefault();
} else {
game.ui.virtualInput.inProgress = false;
+ if(game.settings['controls'] == 'touchpad') {
+ game.ui.virtualInput.children[0].style.display = 'none';
+ }
}
}
cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
});
document.body.addEventListener('mouseup', e => {
cursorMoveEvent(game, e.target, e.clientX, e.clientY, (e.buttons % 2 == 1));
- if(game.settings['controls'] == 'thumbstick') {
+ if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
game.ui.virtualInput.inProgress = false;
+ if(game.settings['controls'] == 'touchpad') {
+ game.ui.virtualInput.children[0].style.display = 'none';
+ }
}
});
document.body.addEventListener('touchmove', e => cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true));
document.body.addEventListener('touchstart', e => {
- if(game.settings['controls'] == 'thumbstick') {
- if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput) {
+ if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
+ if(e.target.closest('.virtual-input-widget') == game.ui.virtualInput || game.settings['controls'] == 'touchpad') {
game.ui.virtualInput.inProgress = true;
+ game.ui.virtualInput.children[0].style.display = 'block';
e.preventDefault();
} else {
game.ui.virtualInput.inProgress = false;
+ if(game.settings['controls'] == 'touchpad') {
+ game.ui.virtualInput.children[0].style.display = 'none';
+ }
}
}
cursorMoveEvent(game, e.target, e.touches[0].clientX, e.touches[0].clientY, true);
game.ui.moveToPage('pause', true);
e.preventDefault();
}
- if(game.settings['controls'] == 'thumbstick') {
+ if(game.settings['controls'] == 'touchpad' || game.settings['controls'] == 'thumbstick') {
cursorMoveEvent(game, e.target, 0, 0, false);
game.ui.virtualInput.inProgress = false;
+ if(game.settings['controls'] == 'touchpad') {
+ game.ui.virtualInput.children[0].style.display = 'none';
+ }
}
});
document.body.addEventListener('keydown', e => keyboardEvent(game, e.key, 'down'));
const ui = game.ui.root.querySelector('.ui-page.options');
game.settings['controls'] = ui.querySelector('input[name="upInTheAirGame-controls"]:checked').value;
const virtualInput = game.ui.root.parentNode.querySelector('.virtual-input-widget');
+ virtualInput.children[0].style.display = 'block';
+ virtualInput.children[0].style.left = '50%';
+ virtualInput.children[0].style.top = '50%';
+ delete virtualInput.inProgress;
if(game.settings['controls'] == 'touchpad') {
virtualInput.classList.remove('thumbstick');
virtualInput.classList.add('touchpad');
game.ui.root.classList.remove('control-mouse', 'control-thumbstick');
game.ui.root.classList.add('control-touchpad');
+ virtualInput.children[0].style.display = 'none';
} else if(game.settings['controls'] == 'thumbstick') {
virtualInput.classList.remove('touchpad');
virtualInput.classList.add('thumbstick');