是否可以在框架中获取触摸事件(在移动浏览器上)?
Is it possible to get touch events in a-frame (on mobile browser)?
我试过向我的 aframe 实体添加一个 onclick 事件,如下所示:
<a-sphere id="sphere1" onclick="moveSphere()"
position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
但它不适用于移动设备。
或者,我试过像这样添加触摸事件侦听器,但没有任何反应:
sphereElement.addEventListener('touchend', moveSphere);
3D 元素不像 DOM 元素,您不能像 touchend 那样在它们上注册正常的 DOM 事件。您必须在 canvas
上注册它们
为此,您需要像 https://jesstelford.github.io/aframe-click-drag-component/
这样的 raycaster 解决方案
<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>
我试过向我的 aframe 实体添加一个 onclick 事件,如下所示:
<a-sphere id="sphere1" onclick="moveSphere()"
position="0 1.25 -1" radius="1.25" color="#EF2D5E"></a-sphere>
但它不适用于移动设备。
或者,我试过像这样添加触摸事件侦听器,但没有任何反应:
sphereElement.addEventListener('touchend', moveSphere);
3D 元素不像 DOM 元素,您不能像 touchend 那样在它们上注册正常的 DOM 事件。您必须在 canvas
为此,您需要像 https://jesstelford.github.io/aframe-click-drag-component/
这样的 raycaster 解决方案<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>