2017-07-26 25 views
-1

我需要啓用只對A型架,這些在mobileVR模式凝視是我試過的代碼,但不能正常工作任何一個可以請幫我解決這個錯誤請。使目光只針對移動VR模式

var cursorEl = document.querySelector('a-cursor'); 
 
if (!AFRAME.utils.device.isMobile()) 
 
{    
 
document.querySelector('a-scene').addEventListener('enter-vr', function() 
 
{ 
 
cursorEl.parentEl.removeChild(cursorEl); 
 
} 
 
});

在此先感謝

回答

0

您可以簡單地添加/刪除光標與連接到相機組件:

let cursor = document.createElement('a-cursor'); 
this.el.sceneEl.addEventListener('enter-vr', function() { 
    el.appendChild(cursor); 
}) 
this.el.sceneEl.addEventListener('exit-vr', function() { 
    el.removeChild(cursor); 
}) 

你可以看到它是如何工作在這裏:https://jsfiddle.net/gftruj/5uq1vmym/;


如果你想讓它專用於手機,據我看到 AFRAME.utils.device.isMobile()方法是否正常工作,所以你可以只包聽衆在一個檢查:

if(AFRAME.utils.device.isMobile()){ //addListeners } 
+0

我只需要光標移動VR模式爲桌面和移動我正在使用點擊和觸摸控制 – KumareshR

+0

@KumareshR然後,我會包裝聽衆在檢查中所述:)不移動時,輸入/退出vr聽衆將不適用。 –

+0

@KumareshR如果您添加相機引用(document.querySelector('a-camera'))而不是'this.el'/'el',它應該工作,只要腳本在head標籤中,否則它可以做意想不到的事情隨時與小提琴混亂 –