如何在A-Frame中加载新场景?

时间:2016-08-03 08:18:38

标签: aframe webvr

我正在使用A-Frame(JavaScript库)。当用户点击当前场景中的某个组件时,我想加载一个新场景。我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:3)

查看A-Frame Template Component。值得注意的是Swapping Example

您可以在脚本标记内或单独的文件中定义单独的场景。以下是脚本标记模板的示例:

<a-scene>
  <!-- Templates. -->
  <a-assets>
    <script id="scene1" type="text/html">
      <a-box></a-box>
    </script>
    <script id="scene2" type="text/html">
      <a-sphere></a-sphere>
    </script>
  </a-assets>

  <a-entity template="src: #box"></a-entity>
</a-scene>

然后,当您想要更改场景时,请更改src

<a-entity template="src: #sphere"></a-entity>

以下是以间隔编程方式更改模板src的示例组件:https://github.com/ngokevin/kframe/blob/master/components/template/examples/swapping/components/template-looper.js

主要是el.setAttribute('template', 'src', '#sphere');

对于可以帮助更改src的其他组件:

  • Event Set Component可以帮助您收听您的鼠标中心并更改src作为回应。
  • 模板组件还附带template-set组件,该组件将更改事件上的模板。
相关问题