For example, by using camera rig, I want to move from A to B then B to C in just one single click. I normally write “to 0 0 0” in the event “onclick”.
I want trigger both animations “1” and “1_1”. At the moment it is only the “1_1” that is triggered by a click. I’m using a timeline from https://www.npmjs.com/package/aframe-animation-timeline-component
My code can be found in https://glitch.com/edit/#!/winter-deserted-topaz
Advertisement
Answer
The topic is general, so I’ll split it into separate cases:
Firing two simultaneous animations
If the animation components within an entity share an event ( defined in startEvents ) they will all fire at once:
JavaScriptx11111<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
2<a-scene cursor="rayOrigin: mouse">
3<a-box position="0 1 -3" rotation="0 45 0" scale="0.25 0.25 0.25" color="#4CC3D9"
4
5animation__rotation="property: rotation; from: 0 45 0; to: 0 405 0; dur: 4000;
6easing: linear; startEvents: click"
7
8animation__scale="property: scale; from: 0.25 0.25 0.25; to: 1.5 1.5 1.5; dur: 2000;
9dir: alternate; easing: linear; loop: 2; startEvents: click">
10</a-box>
11</a-scene>
Starting an animation after another one is finished
You can wait for one animation to finish and start another one with a bit of javascript.
You can determine if an animation has ended with the animationcomplete__(ID is the ‘name’ string after the animation__ bit) event.
Then you can emit a signal, which starts the second animation:
JavaScript120201<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
2<script>
3AFRAME.registerComponent("animation-manager", {
4init: function() {
5// wait for the first animation to finish
6this.el.addEventListener("animationcomplete__first", e => {
7// start the second animation
8this.el.emit("second")
9})
10}
11})
12</script>
13<a-scene cursor="rayOrigin: mouse">
14<a-box position="0 1 -3" rotation="0 45 0" scale="0.25 0.25 0.25" animation-manager color="#4CC3D9"
15animation__first="property: rotation; from: 0 45 0; to: 0 405 0; dur: 2000;
16easing: linear; startEvents: click"
17animation__second="property: scale; from: 0.25 0.25 0.25; to: 1.5 1.5 1.5; dur: 2000;
18dir: alternate; easing: linear; loop: 2; startEvents: second">
19</a-box>
20</a-scene>