2016-09-28 56 views
0

我尝试添加一个onclick事件到我的AFRAME实体,像这样:是否可以在一帧(在手机浏览器)获得触摸事件?

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

,但它无法在移动工作。

另外,我已经尝试添加触摸事件侦听器,像这样,但没有任何反应:

sphereElement.addEventListener('touchend', moveSphere);

回答

1

3D元素不像DOM元素,你不能对他们的正常注册DOM事件一样touchend。你必须注册它们的canvas

对于工作,你需要像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> 
+0

哦,真的raycaster解决方案?我已经添加onclick,它已经在笔记本电脑上工作。我将在手机上尝试这个组件。谢谢。 – dlgard

+0

它可能没有触摸支持,但是如果你想要拖动东西,总体思路是正确的。 – ngokevin

+0

我曾尝试使用这种方法,但我得到一个错误,registerAframeClickDragComponent未定义。 – Shreya

相关问题