在发出事件触发效果时,在 js 中更改动画的 'to' 不起作用

Changing animation's 'to' in js doesn't work when emitting an event to trigger the effect

我正在尝试为这个父相机实体播放一个简短的旋转动画。我有以下动画:

<a-animation attribute="rotation" dur="1000" to="0 163.5761975835419 0" fill="forwards" begin="rotateCam"></a-animation>

然后,我尝试设置 'to' 属性 before emitting rotateCam (with animation.setAttribute(...)),但它只播放我在 HTML 中设置的默认旋转。我错过了什么吗?

例如,参见此 fiddle。 v0.5.0.

感谢您的宝贵时间。

经过一些研究并在 A-Frame Slack 上与 dirkk0 交谈后,很明显他们正在采用 component-based 方法。我更改了我的代码以应用 ngokevin 的动画组件,它解决了我的问题! :)

Relevant test (AFrame v0.5.0)

HTML:

<a-scene>
  <a-sphere position="0 1.25 -5" radius="1.25" color="#EF2D5E"></a-sphere>
  <a-box position="-1 0.5 -3" width="1" height="1" depth="1" color="#4CC3D9" animation="property: rotation; dur: 1000; startEvents: rotateBox"></a-box>
  <a-cylinder position="1 0.75 -3" radius="0.5" height="1.5" color="#FFC65D"></a-cylinder>
  <a-plane position="0 0 -4" rotation="-90 0 0" width="4" height="4" color="#7BC8A4"></a-plane>

  <a-sky color="#ECECEC"></a-sky>
</a-scene>

JS:

setTimeout(() => {
  let box = document.querySelector('a-box');

  box.setAttribute('animation', 'to', '0 20 0');
  box.emit('rotateBox');
}, 2000);