Jump to content

Repeat chained yoyo tweens?


Lawen
 Share

Recommended Posts

Hi everyone!

 

I want to create a little shaking effect on an object.

 

My idea is to start a tween that moves the obj to {x: obj.x-10}, yoyo that so it comes back to its original position, and once is finish, chain another tween to the other side, {x: obj.x+10}, which is also with yoyo(true).

var targetVariationX = obj.x;var targetVariationY = obj.y;var shakeTween1 = game.add.tween(obj).to({x:targetVariationX - 10}, time);shakeTween1.yoyo(true);		var shakeTween2 = game.add.tween(obj).to({x:targetVariationX + 10}, time);shakeTween2.yoyo(true);shakeTween1.chain(shakeTween2);shakeTween1.start();

The problem comes when I try to set .repeat(#) to any of the tweens. It only repeats one of them, not the hole chained tweens.

 

Any idea?

Link to comment
Share on other sites

  • 3 months later...

Not sure if you're still looking for this, but I already posted a similar shake effect using tweens in this thread and combine it with this example then you can do this:

// shake it 10 pixels, 3 timesgame.add.tween(obj).to({x: targetVariationX-10}, time).to({x: targetVariationX+10}, time).repeatAll(3).start(); 
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...