我正在使用 A-Frame(JavaScript 库)。当用户单击当前场景中的某个组件时,我想加载一个新场景。我怎样才能做到这一点?
问问题
4420 次
1 回答
4
查看A-Frame 模板组件。尤其是交换示例。
您可以在脚本标签或单独的文件中定义单独的场景。这是一个带有脚本标记模板的示例:
<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 的组件:
- 事件集组件可以帮助监听你的 mouseenter 并改变
src
响应。 - 模板组件还带有
template-set
将在事件上更改模板的组件。
于 2016-08-03T09:01:10.243 回答