Timer + Aframe : 如何使用 setTimeOut for Aframe.registercomponent( "..." )



我知道这是一个初学者的问题,但我在html/javascript方面遇到了一些麻烦。我了解了setTimeout(函数,时间(,并且知道如何通过创建函数来使用它。然而,我想知道是否可以将此setTimeOut用于Aframe.registercomponent的其他脚本?我没有在上面找到任何东西,我所有的尝试都失败了。

例如"音频分析器波形":

AFRAME.registerComponent('audioanalyser-waveform', {
dependencies: ['audioanalyser'],
schema: {
maxHeight: {default: 0.2},
multiplier: {default: .01},
radius: {default: 1},
},
init: function () {
this.colors = [];
this.geometry;
this.levels = [];
this.noisePos = 0;
this.rings = [];
},

update: function () {
setTimeout(Color, 4000);
var data = this.data;
var el = this.el;
var i; 
...
...

这个在我的wave.js脚本中我知道我可以在我的index.html中用标签来称呼它:

<a-entity id="analyser"
audioanalyser="src: #song"
audioanalyser-waveform="radius: 1"
rotation="210 0 0"
position="0 100 -150"
></a-entity>

如果我能加上这一点,事情就会很简单:

<script> setTimeout(audioanalyser-waveform, 4000); </script>

但它不是这样工作的,我不知道如何设置Aframe.registercomponent的开始/停止来选择其播放秒数。

你能帮我吗。。。

Pulsar,

您想要实现什么?你能有一个组件在4000ms后设置audioanalyser-waveform吗?

<a-entity id="analyser"
audioanalyser="src: #song"
rotation="210 0 0"
position="0 100 -150"
your-component
></a-entity>

组件代码:

AFRAME.registerComponent('your-component', {
...
init: function () {
setTimeout(() => {
this.el.setAttribute('audioanalyser-waveform', {radius: 1});
}, 4000)
}
...
});

最新更新