2017-07-07 73 views
0

我從aframe文檔中讀到,無論何時更新位置或任何其他值,附加組件的更新都會觸發,我只是試圖在每個位置更改上觸發更新。更新不在AFAME組件中觸發

這是組件: -

 AFRAME.registerComponent('checking', { 
      init: function(){ 
      console.log("initialized"); 
      }, 
      update: function(){ 
      console.log("valueUpdated: "+this.el.id); 
      }, 
      tick: function(){ 

      } 
     }); 

更新當文檔被加載正在使用init被觸發一次,但不是當我這樣做從控制檯像obj.setAttribute("position","4 6 7"); ACC的文檔應該發生對或者我犯了一些非常基本的錯誤?

謝謝...

回答

1

我想你混淆了一個組件與實體。實體是一個容器,其行爲和外觀通過組件定義。
所以更新函數會在開始時觸發+當您更改組件時,比如通過setAttribute('checking','newValue')。


你可以做你的檢查或者通過:

包括爲「componentChanged」事件的監聽:

this.el.addEventListener('componentChanged',function(e){ 
     if(e.detail.name==='position'){ 
      console.log(e.detail.newData); 
     } 
    }); 

檢查,如果位置上打勾改變,但似乎非常inneficient:

init(){ 
    this.pos = this.el.getAttribute('position'); 
    } 
    tick: function(){ 
    if(this.el.getAttribute('position') != this.pos){ 
     this.pos = this.el.getAttribute('position'); 
    } 
    } 
+0

哦...知道了.....感謝亞當 – user287332