How to load a new scene in A-Frame?

穿精又带淫゛_ 提交于 2019-12-01 12:20:30
ngokevin

Check out the A-Frame Template Component. Notably the Swapping Example.

You can either define your separate scenes within script tags or within separate files. Here is an example with script tag templating:

<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>

Then when you want to change your scene, change the src:

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

Here is an example component to programmatically change template src on interval: https://github.com/ngokevin/kframe/blob/master/components/template/examples/swapping/components/template-looper.js

Mainly it will be el.setAttribute('template', 'src', '#sphere');

For other components that could assist changing the src:

  • Event Set Component can help listen to your mouseenter and change the src in response.
  • The template component also comes with template-set component that will change the template on an event.
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!