首页 > 解决方案 > A-Frame:rayOrigin光标和鼠标同时

问题描述

我已经实现了这个例子中的事件: https ://aframe-event-set-component.glitch.me/

这些事件现在听我的光标或我的鼠标。如何在一个应用程序中结合这两种方法,以便可以通过鼠标和光标触发事件?就像这里:
https ://github.com/mayognaise/aframe-mouse-cursor-component (最新的A-Frame不再支持)

我可以写类似的东西cursor="rayOrigin: mouse && cursor"吗?

此致!

标签: cursormouseaframe

解决方案


至于click事件:它似乎与两个cursor组件一起工作:一个在 中a-scene,一个在相机中:

<a-scene cursor="rayOrigin: mouse">
  <a-camera position="0 1.6 0">
    <a-entity cursor="fuse: true; fuseTimeout: 500" position="0 0 -1" geometry="primitive: ring; radiusInner: 0.02; radiusOuter: 0.03" material="color: black; shader: flat">
    </a-entity>
  </a-camera>
</a-scene>

在这个小提琴中检查它。


另一方面,a-scenes 光标似乎搞乱了其他事件。您可以提出问题,或创建一个组件,该组件会在发出事件cursor时移除鼠标。enter-vr

...
this.el.sceneEl.addEventListener("enter-vr", function() {
  this.el.removeAttribute("cursor")
})
this.el.sceneEl.addEventListener("exit-vr", function() {
  this.el.setAttrubute("cursor", "rayOrigin", "mouse")
})

推荐阅读