如何在Aframe中分开鼠标单击事件和路线单击事件 [英] how separate the mouse click event and the courser click event in Aframe

查看:354
本文介绍了如何在Aframe中分开鼠标单击事件和路线单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AFRAME创建VR编辑器...
我需要在用户用鼠标单击元素时创建一个事件,并在用Aframe相机光标单击时执行不同的操作。

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.

我发现了< a-scene cursor = rayOrigin:mouse> ,但这会在鼠标和光标都单击。
是否可以在AFRAME中使用?

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?

推荐答案

用游标元素进行区分:

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

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

这篇关于如何在Aframe中分开鼠标单击事件和路线单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆