tween.js icon indicating copy to clipboard operation
tween.js copied to clipboard

Does chaining really mean sequence?

Open khurramraheel opened this issue 12 years ago • 6 comments

I am new to tween.js and wonder why the following tween does not run the two animations in sequence. I assumed that x in the first animation will be set to 200 and after getting completed, the second animation will start i.e set y to 500 but they are running in parallel.

Am I missing something

var tween = new TWEEN.Tween(shape.position).to({x:200}).to({y:500}); tween.start();

//tween update code not shown for simplicity

khurramraheel avatar May 30 '14 04:05 khurramraheel

Hey @khurramraheel , sorry I got back to you so late-I'd swear I'd answered your question. The issue is that every time you call to it overwrites any possible value you had already specified. If you want to do two different 'animations' sequentially you should create two tweens and chain them-that's what chaining means in our context. So you'd do this:

var tween = new TWEEN.Tween(shape.position).to({ x: 200 })
  .chain(new TWEEN.Tween(shape.position).to({ y: 500 }))
  .start();

hope that makes things clearer.

sole avatar Jun 15 '14 21:06 sole

I got your point, Thanks!

khurramraheel avatar Jun 16 '14 07:06 khurramraheel

Hey @khurramraheel , sorry I got back to you so late-I'd swear I'd answered your question. The issue is that every time you call to it overwrites any possible value you had already specified. If you want to do two different 'animations' sequentially you should create two tweens and chain them-that's what chaining means in our context. So you'd do this:

var tween = new TWEEN.Tween(shape.position).to({ x: 200 })
  .chain(new TWEEN.Tween(shape.position).to({ y: 500 }))
  .start();

hope that makes things clearer.

it seems that if the two 'animations' has their own 'onUpdate' function call, i will lose efficacy

mengxun1437 avatar Aug 02 '22 11:08 mengxun1437

@mengxun1437 how so?

trusktr avatar Aug 04 '22 07:08 trusktr

@mengxun1437 how so?

I'm sorry, I may have misunderstood due to my knowledge of tweenjs When we use chain, we need to use Group's update API🙏

mengxun1437 avatar Aug 04 '22 08:08 mengxun1437

No prob (solved in the other issue). If any ideas, let us know. :)

trusktr avatar Aug 04 '22 23:08 trusktr