点击移动设备无法在aframe vr模式下工作

时间:2018-06-09 16:28:40

标签: aframe

我做了一个afr vr世界,当你不在vr模式时,如果你点击,它会让你前进。但是,每当我在移动设备上切换到vr模式时,攻丝都不起作用。此外,当您在移动设备上点按任何模式时,屏幕会变暗?

<script src="https://aframe.io/releases/0.8.2/aframe.min.js"></script>
<script>
  AFRAME.registerComponent("foo", {
    init: function() {
      this.mouseDown = false
      this.el.addEventListener("mousedown", (e) => {
        this.mouseDown = true
      })
      this.el.addEventListener("mouseup", (e) => {
        this.mouseDown = false
      })
    },
    tick: function() {
      if (this.mouseDown) {
        let pos = this.el.getAttribute("position")
        let mesh = this.el.object3D
        var matrix = new THREE.Matrix4();
        var direction = new THREE.Vector3(0, 0, -0.1);

        matrix.extractRotation(mesh.matrix);
        direction.applyMatrix4(matrix)
        direction.add(new THREE.Vector3(pos.x, pos.y, pos.z))
        this.el.setAttribute("position", direction)
      }
    }
  })

</script>
<a-scene>
  <a-torus-knot color="red" arc="90" p="3" q="8" radius="3" radius-tubular="0.2" position="0 0 -10"></a-torus-knot>

  <a-camera id="theCamera" position="0 1 5" wasd-controls="acceleration: 100" foo>
    <a-cursor color="red" />
  </a-camera>

</a-scene>

1 个答案:

答案 0 :(得分:0)

1)事件正常,相机不动。

2)a-frame阻止任何js代码在移动时在vr模式下尝试setAttribute("position", newPos)的时间/事件。不确定原因,但有一种解决方法:将相机放在容器中,然后移动容器:

<a-entity id="thecamera">
  <a-camera position="0 1 5" wasd-controls="acceleration: 100">
    <a-cursor color="red" />
  </a-camera>
</a-entity>

工作故障here。您可以重用previous question中的代码,我已将其移至场景中,只是为了确保在vr / vr离开时帧没有切换摄像机。