Ninjadoodle Posted March 21, 2018 Report Share Posted March 21, 2018 Hi @enpu I have a couple of tweens inside a class, and I'm trying to bind one of the tween to the other tweens onComplete function, in order to restart it. I can't however get this to work. Is this possible or is my setup completely wrong? this.tween1 = game.Tween.add(this.sprite, { x: 640, y: 640 }, 2000, { easing: 'Quadratic.In' }).start(); this.tween2 = game.Tween.add(this.sprite, { x: x, y: y }, 2000, { easing: 'Quadratic.Out' }).onComplete(function() { this.start(); }.bind(this.tween1)).stop(); }, update: function() { var distance = this.sprite.position.distance(game.scene.playerShip.sprite.position); if (distance < 128 + 128) { this.tween1.stop(); this.tween2.start(); } } Link to comment Share on other sites More sharing options...
enpu Posted March 21, 2018 Report Share Posted March 21, 2018 @Ninjadoodle So you want tween1 to start when tween2 is completed? Try chain function. this.tween2.chain(this.tween1); Link to comment Share on other sites More sharing options...
Ninjadoodle Posted March 21, 2018 Author Report Share Posted March 21, 2018 @enpu - hmmmm thats not working - maybe because I'm stopping tween1, when it's 'hitting' the player ship. I seem to make things difficult for my self Link to comment Share on other sites More sharing options...
enpu Posted March 21, 2018 Report Share Posted March 21, 2018 @Ninjadoodle Ah, well you can use pause and resume functions. Or then if you need for the tween to start from beginning, then you need to create new one. startTween1: function() { this.tween1 = game.Tween.add(this.sprite, { x: 640, y: 640 }, 2000, { easing: 'Quadratic.In' }).start(); }, startTween2: function() { this.tween2 = game.Tween.add(this.sprite, { x: x, y: y }, 2000, { easing: 'Quadratic.Out', onComplete: this.startTween1.bind(this) }).start(); }, update: function() { var distance = this.sprite.position.distance(game.scene.playerShip.sprite.position); if (distance < 128 + 128) { this.tween1.stop(); this.startTween2(); } } Ninjadoodle 1 Link to comment Share on other sites More sharing options...
Ninjadoodle Posted March 21, 2018 Author Report Share Posted March 21, 2018 @enpu - Thanks, I think I understand - I was trying to restart the tween. Thank you for the help!! Link to comment Share on other sites More sharing options...
Recommended Posts