[LayaAir2]多指触摸在电脑上检测不出来,理论上要检测出来才对的!

引擎版本 2.13.3 
 
一直有这个问题,PC上检测不出多指的触摸的,必须是手机模式才可以,这个是属于 BUG 吗?
 
import Input3D = Laya.Input3D;
import Vector2 = Laya.Vector2;

/**
* 手指。
*/
export class Finger {
public id: number = 0;
public position: Vector2 = new Vector2();
public deltaPosition: Vector2 = new Vector2();

constructor(id?: number) {
if (id != undefined) {
this.id = id;
}
}
}

/**
* 触摸监听者接口。
*/
export interface ITouchListener {
onTouchDown(finger: Finger);
onTouchSwipe(finger: Finger);
onTouchUp(finger: Finger);
}

/**
* 多点触摸。
*/
export class Touch {

private input: Input3D;

private touchCount: number = 0;

private touches: Map<number, Laya.Touch> = new Map<number, Laya.Touch>();
private oldTouches: Map<number, Laya.Touch> = new Map<number, Laya.Touch>();
private fingers: Map<number, Finger> = new Map<number, Finger>();

private listener: ITouchListener;

constructor(input: Input3D) {
this.input = input;

if (Laya.Browser.onPC) {

}
}

dispose() {
if (Laya.Browser.onPC) {

}
}

public setListener(listener: ITouchListener) {
this.listener = listener;
}

/** 帧更新函数中调用。 */
public update() {
this.touchCount = this.input.touchCount(); // 这个在 PC 上永远是 0。

// copy touches.
if (this.oldTouches.size > 0) {
this.oldTouches.clear();
}
for (let [key, value] of this.touches) {
this.oldTouches.set(key, value);
}

// reset touches.
if (this.touches.size > 0) {
this.touches.clear();
}

// get touches.
for (let i = 0; i < this.touchCount; ++i) {
let touch = this.input.getTouch(i);
// this.touches.set(touch.identifier, touch); // iOS 上是一个不确定的很小的负数,并不是0开始的,且每点击一次都会-1,所以有问题。
this.touches.set(i, touch);
}

// fingers gesture.
for (let [key, value] of this.touches) {
// get finger.
let finger = this.fingers.get(key)
if (finger == undefined) {
finger = new Finger();
finger.id = key;
this.fingers.set(key, finger);
}

if (this.oldTouches.has(key)) {
// downing.
finger.deltaPosition.x = value.position.x - finger.position.x;
finger.deltaPosition.y = value.position.y - finger.position.y;
finger.position.x = value.position.x;
finger.position.y = value.position.y;

if (finger.deltaPosition.x != 0 || finger.deltaPosition.y != 0) {
// console.log("Swipe", key, Date.now());
if (this.listener) this.listener.onTouchSwipe(finger);
}
}
else {
// down start.
finger.deltaPosition.x = 0;
finger.deltaPosition.y = 0;
finger.position.x = value.position.x;
finger.position.y = value.position.y;

// console.log("Down", key);
if (this.listener) this.listener.onTouchDown(finger);
}
}

for (let key of this.oldTouches.keys()) {
if (!this.touches.has(key)) {
// up.
// console.log("Up", key);
if (this.listener) this.listener.onTouchUp(this.fingers.get(key));
}
}
}

}
已邀请:

Laya_Fred

赞同来自:

您好,这个问题不属于bug,chrome在PC端因为只有一个鼠标输入是无法模拟多指触控的,即使在开发者窗口开启手机模式也只能模拟到一个touch内容,您可以在手机chrome上触发多指触控,并通过手机的开发调试功能,在PC的chrome上使用inspect功能来debug手机端的chrome内容,可以看下类似这个文档的内容 PC端chrome浏览器如何调试多点触控事件/chrome浏览器远程调试手机上的网页

要回复问题请先

商务合作
商务合作