KumareshR KumareshR - 3 years ago 72
Javascript Question

enabling gaze only for mobile VR mode

I need to enable the gaze only for the mobileVR mode in A-Frame these is the code I have tried but not working properly can any one please help me to solve this error please.



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





Thanks in advance

Answer Source

You can simply add/remove the cursor with a component attached to the camera:

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);
})

You can see how it works here: https://jsfiddle.net/gftruj/5uq1vmym/;


If You want to make it exclusive for mobile, as far as i see the AFRAME.utils.device.isMobile() method is working properly, so You could just wrap the listeners in a check:

if(AFRAME.utils.device.isMobile()){ //addListeners }
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download