1

I have written several methods does separate animations in my scene. However, I want to have each animation play after the previous one is finished.

Like if I have 2 different animation methods like moveObject1(x) and moveObject2(x) where x is the amount the object will move, how could I tell if moveObject1 is done moving x amount to run moveObject2?

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Hannah Bernal
  • 133
  • 1
  • 1
  • 10
  • You must either fire each function as a callback function once your completion condition is met or consider using some advanced libraries like [tween.js](http://www.createjs.com/tweenjs) that can help with sequencing. – Anurag Srivastava Mar 01 '19 at 16:21
  • Tween is good, also maybe you want to read on mediator pattern: https://stackoverflow.com/questions/25417547/observer-pattern-vs-mediator-pattern might help to organize your code. – Alex Pakka Mar 01 '19 at 18:11
  • @AnuragSrivastava Thank you for the response! Would there be any examples that use tween.js to call the animations in order? – Hannah Bernal Mar 03 '19 at 00:20
  • Well, google is your friend here. :) – Anurag Srivastava Mar 03 '19 at 00:22
  • @AnuragSrivasta Okay, I'll look into that then! Wondering if it can also work for more complex animations, like simultaneous rotation and position changes? – Hannah Bernal Mar 03 '19 at 02:27
  • Oh yes, it is quite an advanced library, search for examples of tweenjs with threejs. – Anurag Srivastava Mar 03 '19 at 06:39
  • @AnuragSrivastava I've been searching for a while in tweenjs but now I'm wondering if it's chaining method can use existing animation functions that I made? I see that you could do simple one's like changing the position. But what if you already have complex animation methods that you want to call in order? – Hannah Bernal Mar 04 '19 at 02:08
  • Added a basic example as an answer, see if it helps you. – Anurag Srivastava Mar 04 '19 at 07:06

0 Answers0