Compare commits
2 commits
3997e94a68
...
fe22b85387
Author | SHA1 | Date | |
---|---|---|---|
fe22b85387 | |||
41cb894ef9 |
3 changed files with 48 additions and 1 deletions
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"touchscreen": {
|
||||
"mode": "joystick",
|
||||
"mode": "swipe",
|
||||
"deadzone": 10,
|
||||
"buffer": false
|
||||
},
|
||||
|
|
19
assets/metaConfig.json
Normal file
19
assets/metaConfig.json
Normal file
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
"touchscreen": {
|
||||
"mode": [
|
||||
"crosspad",
|
||||
"joystick",
|
||||
"swipe"
|
||||
],
|
||||
"deadzone": {
|
||||
"min": 1,
|
||||
"max": 100
|
||||
}
|
||||
},
|
||||
"gamepad": {
|
||||
"deadzone": {
|
||||
"min": 0,
|
||||
"max": 1
|
||||
}
|
||||
}
|
||||
}
|
|
@ -177,4 +177,32 @@
|
|||
});
|
||||
}
|
||||
|
||||
if(config.touchscreen.mode=='swipe') {
|
||||
let center={x: 0, y: 0};
|
||||
window.center=center;
|
||||
window.addEventListener('touchstart', e => {
|
||||
center.x=e.touches[0].clientX;
|
||||
center.y=e.touches[0].clientY;
|
||||
});
|
||||
window.addEventListener('touchmove', e => {
|
||||
let x=e.touches[0].clientX-center.x;
|
||||
let y=e.touches[0].clientY-center.y;
|
||||
const angle=((Math.atan2(x, y)+2*Math.PI)%(2*Math.PI))/Math.PI;
|
||||
const magnitude=Math.hypot(x, y);
|
||||
|
||||
let inputs=currentInputs;
|
||||
if(magnitude>config.touchscreen.deadzone) {
|
||||
if(angle>.25 && angle <.75) inputs.right=true;
|
||||
else if(angle>.75 && angle<1.25) inputs.up=true;
|
||||
else if(angle>1.25 && angle<1.75) inputs.left=true;
|
||||
else inputs.down=true;
|
||||
|
||||
center.x=e.touches[0].clientX;
|
||||
center.y=e.touches[0].clientY;
|
||||
}
|
||||
|
||||
if(!config.touchscreen.buffer) inputs.clearBuffer=true;
|
||||
});
|
||||
}
|
||||
|
||||
})();
|
||||
|
|
Loading…
Reference in a new issue