简体   繁体   English

是否可以通过框架(在移动浏览器上)获得触摸事件?

[英]Is it possible to get touch events in a-frame (on mobile browser)?

I've tried adding an onclick event to my aframe entity, like so: 我试图将onclick事件添加到我的aframe实体中,如下所示:

<a-sphere id="sphere1" onclick="moveSphere()" position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>

but it doesn't work on mobile. 但不适用于移动设备。

alternatively, I've tried adding touch event listeners like so, but nothing happens: 或者,我尝试像这样添加触摸事件侦听器,但没有任何反应:

sphereElement.addEventListener('touchend', moveSphere);

3D elements aren't like DOM elements, you can't register normal DOM events on them like touchend. 3D元素与DOM元素不同,您不能在它们上注册普通的DOM事件,如touchend。 You'd have to register them on the canvas 您必须在canvas上注册它们

For that to work, you'd need a raycaster solution like https://jesstelford.github.io/aframe-click-drag-component/ 为此,您需要一个光线广播解决方案,例如https://jesstelford.github.io/aframe-click-drag-component/

<head>
  <script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
  <script src="https://unpkg.com/aframe-click-drag-component"></script>
  <script>
    registerAframeClickDragComponent(window.AFRAME);
  </script>
</head>

<body>
  <a-scene>
    <a-sphere click-drag position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
    <a-camera look-controls-enabled="false"></a-camera>
  </a-scene>
</body>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM