jbaumann Posted November 6, 2013 Share Posted November 6, 2013 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 More sharing options...
shnfara Posted March 22, 2017 Share Posted March 22, 2017 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 More sharing options...
Tom Atom Posted March 23, 2017 Share Posted March 23, 2017 Setting pendingDelete to false is half way solution. To prevent some timing issues (like running your tween faster than it should), you also have to remove it from update queue immediatelly. In one older thread I posted solution I use: Link to comment Share on other sites More sharing options...
Recommended Posts