how separate the mouse click event and the courser click event in Aframe

自作多情 提交于 2019-12-08 07:51:24

问题


I'm creating a VR Editor using AFRAME... I need to create an event when the user clicks on an element by mouse and to do deferent action when clicking by Aframe camera cursor.

I found the <a-scene cursor="rayOrigin: mouse"> but this would do the same click event on both mouse and cursor click. is that possible in AFRAME?


回答1:


Discriminate by the cursor element:

AFRAME.registerComponent('on-click', {
    init: function () {
      var self = this;
      this.el.addEventListener('click', function (evt) {
        if (self.el.sceneEl === evt.detail.cursorEl) {
          console.log("MOUSE");
        } else {
          console.log("CURSOR");
        }
      });
    }
  });

Example: https://glitch.com/edit/#!/winter-sagittarius



来源:https://stackoverflow.com/questions/56321191/how-separate-the-mouse-click-event-and-the-courser-click-event-in-aframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!