Jump to content

Stopping and Starting Chained Tweens


jbaumann
 Share

Recommended Posts

Just learning Phaser and trying out tweens. I want to be able to save a chain of tweens and start and stop them.

I'm using the code below - the sprite will run trough the chained tween once, get restarted and then start the tween again only to stop before tween 4 begins. Right now I am overkilling it by stopping and rechaining, but originally I stoppped only tween1 and restarted that and had the same result.

 

What is the best way to do this? Thanks!

function create() {    targetSprite = game.add.sprite(-200,game.world.centerY-250,'target');    var pathXSeg = (game.width + 100 )/4.0;    var yoff = game.world.centerY-250;    targetTween1 = game.add.tween(targetSprite).to({ x: pathXSeg, y: yoff - 100 }, 1000, Phaser.Easing.Linear.None,false,0,false);    targetTween2 = game.add.tween(targetSprite).to({ x: pathXSeg*2, y: yoff + 100 }, 1000, Phaser.Easing.Linear.None,false,0,false);    targetTween3 = game.add.tween(targetSprite).to({ x: pathXSeg*3, y: yoff - 100 }, 1000, Phaser.Easing.Linear.None,false,0,false);    targetTween4 = game.add.tween(targetSprite).to({ x: pathXSeg*4, y: yoff + 100 }, 1000, Phaser.Easing.Linear.None,false,0,false);    targetTween1.chain(targetTween2);    targetTween2.chain(targetTween3);    targetTween3.chain(targetTween4);    targetTween1.start();        } //create()function update() {if(targetSprite.x >= game.width) {    targetTween1.stop();    targetTween2.stop();    targetTween3.stop();    targetTween4.stop();    console.log('Target restart Tween');    targetSprite.x = -200;    targetTween1.chain(targetTween2);    targetTween2.chain(targetTween3);    targetTween3.chain(targetTween4);    targetTween1.start();}}//update()
Link to comment
Share on other sites

  • 3 years later...

Your chained tweens are being removed when executed, make sure you set .pendingDelete = false; on each tween.  I'm not sure if it matters or not, but I set pendingDelete to false after I rechained the tweens (as you did above) and called start() on the first tween.  This solved the problem for me.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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