@woosh/meep-engine
Version:
Pure JavaScript game engine. Fully featured and production ready.
32 lines (23 loc) • 583 B
JavaScript
/**
*
* @param {TouchList} touchList
* @param {Vector2} result
*/
export function getTouchCenter(touchList, result) {
const length = touchList.length;
let x = 0, y = 0;
if (length > 0) {
for (let i = 0; i < length; i++) {
const touch = touchList.item(i);
if (touch === null) {
continue;
}
x += touch.clientX;
y += touch.clientY;
}
// average to get center
x /= length;
y /= length;
}
result.set(x, y);
}