Aフレームでアニメーションを巻き戻します
Nov 26 2020
私はa-video
自分のシーンのどこかにいます。その横にある[+]ボタンをクリックすると、アニメーションがトリガーされて拡大されます。また、元のサイズに縮小するために-ボタンが表示されます。
あまり問題なくアップサイジング部分を作ることができましたが、アニメーションを逆にして、ビデオを元のスケールに戻す方法が見つかりませんでした。
これが私がこれまでに持っているものです(簡潔にするために適応されています):
<a-video animation="property: scale; to: 20 20 20; dur: 200; dir: alternate; startEvents: startplay" src="#myvid" id="avideo"></a-video>
<a-image src="#play" onclick="document.getElementById('avideo').emit('startplay')"></a-image>
<a-image src="#pause" onclick="????"></a-image> <!-- is it possible to play the animation rewind here since I specified dir: alternate on #avideo? -->
アップスケーリングアニメーションは正常に機能しますが、コメントで説明されているように巻き戻し部分をトリガーする方法が見つかりません。
私はAFrameにかなり慣れていません。おそらく単純なことですが、答えは私のような新人に役立つ可能性があります。
ありがとうございました
回答
PiotrAdamMilewski Nov 26 2020 at 20:40
私は2番目のアニメーションでそれをやってみます:
- 1つはあなたが望むことをします
- もう1つは、現在の状態から「元の」状態に戻ります。
あなたと少し似た設定で言いましょう
<a-sphere animation__play="property: scale; from: 1 1 1; to: 5 5 5; dur: 2000; dir: alternate; startEvents: play-anim; pauseEvents: pauseA-anim; stopEvents: stop-anim; loop: true"
animation__rewind="property: scale; to: 1 1 1; easing: linear; startEvents: rewind-anim"
animation-manager>
</a-sphere>
animation-manager
なりますカスタムコンポーネントのすべてのロジックを含みます:
// custom component declaration
AFRAME.registerComponent("animation-manager", {
// called upon initialization
init: function() {
// manage pressing the play image / button
playBtn.addEventListener("click", e => this.el.emit("play-anim"));
// manage the rewind image / button
rewindBtn.addEventListener("click", e => {
// set the current scale as the "starting point"
this.el.setAttribute("animation__rewind", "from", this.el.getAttribute("scale"))
// pause the current animation
this.el.emit("pause-anim")
// play the rewind animation
this.el.emit("rewind-anim")
})
}
})
それをチェックアウトここに。