Aframe 如何更新A-Frame中的实体或对象?
我正在使用一个可以用HTML编码的组件。例如,使用,我创建了文本:Aframe 如何更新A-Frame中的实体或对象?,aframe,Aframe,我正在使用一个可以用HTML编码的组件。例如,使用,我创建了文本: <a-entity text="text: 0"></a-entity> 如何更新text组件的text属性 就像更新普通DOM元素一样,我们可以使用setAttribute el.setAttribute('visible', false); 如果一个组件有多个属性,我们有三个参数。组件名称、属性名称、值: el.setAttribute('material', 'color', 'black
<a-entity text="text: 0"></a-entity>
如何更新text
组件的text
属性
就像更新普通DOM元素一样,我们可以使用setAttribute
el.setAttribute('visible', false);
如果一个组件有多个属性,我们有三个参数。组件名称、属性名称、值:
el.setAttribute('material', 'color', 'black');
el.setAttribute('text', 'text', '1');
该代码放在哪里?在一个组件内,最好:
AFRAME.registerComponent('update-text-every-second', {
init: function () {
var el = this.el;
var i = 0;
setInterval(function () {
el.setAttribute('text', 'text', i.toString());
}, 1000);
}
});
和使用:
<a-entity text="text: 0" update-text-every-second></a-entity>