【问题标题】:Aframe: Cursor click event not triggering on desktopAframe:光标单击事件未在桌面上触发
【发布时间】:2017-01-31 03:39:04
【问题描述】:

点击事件不会在设置了光标侦听器的实体上触发。这是我的源代码。

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Panorama</title>
    <meta name="description" content="Panorama — A-Frame">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/aframe/0.4.0/aframe.min.js"></script>
    <script type="javascript" >

    AFRAME.registerComponent('cursor-listener', {
      init: function () {
        var COLORS = ['red', 'green', 'blue'];
        this.el.addEventListener('click', function (evt) {
          var randomIndex = Math.floor(Math.random() * COLORS.length);
          this.setAttribute('material', 'color', COLORS[randomIndex]);
          console.log('I was clicked at: ', evt.detail.intersection.point);
        });
      }
    });

    </script>
</head>
<body>
<a-scene>
    <a-sky src="image.jpg" rotation="0 0 0"></a-sky>
    <a-camera fov=60 >
        <a-entity cursor="fuse: false; fuseTimeout: 500;"
                  position="0 0 -1"
                  geometry="primitive: ring; radiusOuter: 0.05; radiusInner: 0.02"
                  material="color: white; shader: flat" >
        </a-entity>
    </a-camera>
    <a-box color="#aa77dd" cursor-listener width="50" height="10" depth="20" position="-7.45 40.00 -141.77" id="Play">
    </a-box>
</a-scene>
</body>
</html>

我尝试在手机和桌面浏览器上执行此操作,但均无效。

【问题讨论】:

  • 你是怎么点击的?
  • 在桌面上,只需用鼠标单击并在手机上触摸框。这能回答你的问题吗?

标签: aframe


【解决方案1】:

光标组件在桌面上工作,鼠标拖动相机查看实体。在移动设备上,它使用保险丝或纸板按钮。在 VR 上,它也是基于注视的。

仅单击鼠标或点击手机时不起作用。看https://github.com/mayognaise/aframe-mouse-cursor-component

【讨论】:

  • 如果我将环拖放到盒子上的相机实体中,盒子应该会改变颜色,对吗?目前,它没有这样做。
  • 拖动+点击桌面。或者将fuse设置为true,让它在拖动后自行点击。
猜你喜欢
  • 2013-05-11
  • 2012-07-30
  • 1970-01-01
  • 2012-08-06
  • 1970-01-01
  • 1970-01-01
  • 2014-01-14
  • 2017-10-17
  • 1970-01-01
相关资源
最近更新 更多