Retroceder uma animação em A-Frame
Eu tenho um a-video
lugar na minha cena. Quando clico em um botão + ao lado dele, uma animação é acionada para aumentá-lo. Também torna visível um botão - para redimensioná-lo ao tamanho original.
Consegui fazer a parte do upsizing sem muitos problemas, mas não consigo encontrar uma maneira de reverter a animação, para fazer o a-video voltar à sua escala original.
Aqui está o que eu tenho até agora (adaptado para ser breve):
<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? -->
A animação de aumento de escala funciona bem, mas não consigo descobrir como acionar a parte de retrocesso conforme descrito nos comentários.
Sou bastante novo no AFrame, provavelmente é algo simples, mas uma resposta pode ajudar novatos como eu.
Obrigado
Respostas
Eu tentaria fazer isso com uma segunda animação:
- um faz o que você quer
- o outro retorna do estado atual para o estado "original".
Digamos com uma configuração um pouco semelhante à sua
<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>
O animation-manager
será um componente personalizado contendo toda a lógica:
// 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")
})
}
})
Confira aqui .