2016-09-28 41 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

相關問題