2016-11-16 64 views
0

我想要獲取動畫以將攝像頭從當前位置移動到從單擊元素傳遞的位置。這個問題似乎是用於將'到'位置傳遞給動畫的正確語法。這是我的。作爲第二個參數傳遞數據的A幀位置動畫

<a-entity id="cam-position" position="0 0 1.2" rotation="-0 0 0"> 
     <a-camera look-controls wasd-controls> 
      <a-entity visible="true" cursor="fuse: true; fuse-timeout: 500" 
       position="0 0 -1" 
       scale="0.01 0.01 0.01" 
       geometry="primitive: sphere" 
       material="color: #6AD7FF; shader: standard"> 
       <a-animation begin="click" 
        easing="ease-in" 
        attribute="scale" 
        dur="2000" 
        fill="backwards" 
        from="0.01 0.01 0.01" to="0.04 0.04 0.04"> 
       </a-animation> 
       <a-animation begin="fusing" 
        easing="ease-in" 
        attribute="scale" 
        fill="forwards" 
        from="1 1 1" to="0.1 0.1 0.1" > 
       </a-animation> 
      </a-entity> 
     </a-camera> 
     <a-animation begin="move" 
        attribute="position" 
        dur="2000" 
        from="0 0 1.2" 
        > 
       </a-animation> 
     </a-entity> 

document.querySelector('#cam-position').emit('move',{'to': { x: 0, y: 0, z: -88 } }); 

它工作正常,沒有第二個參數和在a動畫中指定'to'。有任何想法嗎?謝謝

回答

0

當您發出move時,第二個參數是事件詳細信息。動畫確實有一個功能,可以在事件觸發器上啓動動畫,但它不會查看事件詳細信息。

你需要做一個animation.setAttribute('to', {...})而不是試圖讓事件處理所有事情,因爲這不是一個功能。

document.querySelector('a-animation[begin="move"]').setAttribute('to', '0 0 -88'); 
document.querySelector('#cam-position').emit('move') 
+0

動畫還沒有發生。位置attr更改爲「0 0 -88」,但動畫默認爲舊屬性。控制檯日誌顯示它已更改。相機實體是否需要更新以反映新的「到」位置還是缺少其他東西? –

+0

你也可以試試這個API:https://ngokevin.github.io/kframe/components/animation/ – ngokevin

+0

與kframe /動畫一樣。 –