3

我正在尝试 a-frame,但找不到任何有关如何拖放元素的信息,并且一直在寻找它几个小时!有人熟悉a-frame吗?谢谢

到目前为止,这就是我的代码:

<a-scene>
    <a-cursor></a-cursor>
 <a-assets>
  <img id="enemy-sprite" crossorigin="" src="mustache1.jpg">
 </a-assets>
 <a-image look-at="#player" src="#enemy-sprite" transparent="true" position="0 1.8 -4"></a-image>
 <a-camera id="player" position="0 1.8 0"></a-camera>
 <a-sky src="street.jpg"></a-sky>

编辑:浏览器/home.html:

  <scene scene-id="sceneId"></scene>

浏览器/js/app/directives/screne.html:

  <a-scene>
    <a-sphere click-drag position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
    <a-camera look-controls-enabled="false"></a-camera>
  </a-scene>

索引.html

<script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
<script src="https://unpkg.com/aframe-click-drag-component"></script>
<script>  registerAframeClickDragComponent(window.AFRAME); </script>
4

1 回答 1

6

这不是 Aframe 内置的,但您可以使用 3rd 方组件来获得所需的结果。

aframe-click-drag-component允许在屏幕上单击和拖动实体:

click-drag可以在 3D 场景中单击并拖动具有组件的实体。甚至在相机移动或旋转时也能正常工作!

<head>
  <script src="https://aframe.io/releases/0.3.0/aframe.min.js"></script>
  <script src="https://unpkg.com/aframe-click-drag-component"></script>
  <script>
    registerAframeClickDragComponent(window.AFRAME);
  </script>
</head>

<body>
  <a-scene>
    <a-sphere click-drag position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
    <a-camera look-controls-enabled="false"></a-camera>
  </a-scene>
</body>

查看演示

于 2016-10-09T22:24:56.827 回答