Let's say I've defined a lottie animation using var anim = bodymovin.loadAnimation({<anim data here>})
Now, what i wanna do is something like:
anim.playSegments([80,101]);
console.log("example");
anim.playSegments([102,121]);
The problem here is that console.log is not waiting for the first segment to end in order to run. It runs as soon as the first segment starts.
I understand this due to javascript being synchronous, but is there a way to run this asynchronously? In other words, is there a way for the console.log to wait for the first segment to finish before running?
Play segment -> do something -> play another segment
anim.playSegments([80,101]).then(() => {
console.log("test")
});
anim.playSegments([102,121]);
didn't work. Returns Uncaught TypeError: Cannot read properties of undefined (reading 'then')
anim.playSegments([80,101])
anim.onComplete = function() {
console.log("Test")
}
anim.playSegments([102,121]);
This will run the console.log() after the second segment is complete.
anim.playSegments([80,101])
anim.onComplete = function() {
console.log("frame!");
anim.playSegments([102,121]);
}
this will keep looping the second segment, since it plays it again once it's complete.