jeremyckahn/shifty

Is there a way to update the `to` coordinates of an animation?

kurtextrem opened this issue · 2 comments

E.g. I'm calling the tween function whenever the X/Y coordinates have been updated. This may mean though, that the previous animation doesn't finish fast enough. So the from stays the same, but the to changes. Is this supported here, or would you recommend a different lib?

Hi @kurtextrem! There's no API in Shifty to specifically achieve what you're describing, but I think you could get the results you're looking for by doing something like the following:

  1. Keep track of the timeElapsed value in your tween's stepFunction
  2. Calling .stop() on your tween when the to or from data changes
  3. Start a new tween with the updated to and from data
  4. .seek to the latest timeElapsed value of the previous tween
  5. .resume the tween

I haven't tried this myself so it may need a bit of adjusting. Other libraries might have a better API for this, though I don't which one would be the best to recommend to you.

Thank you. Will try that out.