如何在A帧中加载新场景? [英] How to load a new scene in A-Frame?

查看:59
本文介绍了如何在A帧中加载新场景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用A-Frame(JavaScript库)。当用户单击当前场景中的某个组件时,我想加载一个新场景。我该如何实现?

I am using A-Frame (JavaScript library). I would like to load a new scene when user clicks into a certain component in the current scene. How can I achieve this?

推荐答案

查看 A帧模板组件。值得注意的是交换示例

您可以在脚本标签或单独的文件中定义单独的场景。这是一个带有脚本标签模板的示例:

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>

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

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

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

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

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

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

其他有助于更改src的组件:

For other components that could assist changing the src:


  • 事件集组件可以帮助您监听鼠标并更改 src 作为响应。

  • 模板组件还带有 template-set 组件,该组件将在事件中更改模板。

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

这篇关于如何在A帧中加载新场景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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