Jump to content

Tween stopping


grammka
 Share

Recommended Posts

Its cry  :o

 

I just spent a lot of time on this problem... Plzzz help! How to stop this [%$#!] Tween =/ 

I make chaining tweens and try to stop them in process..

 

I tried many ways..

tweenManager.removeAll();tween.stop();tween.pause();tween = null;player.body.velocity.x = 0;player.body.velocity.y = 0;

..and nothing - character is moving and moving..

 

 

Also I tried do smth like this:

function goTween () {	tween.to({x: ..., y: ...}, 300, Phaser.Easing.Linear.None).start();}function moveTo (path) {	if (tween) tween.stop();		tween = game.add.tween(player.body);		tween.onComplete.add(function () {		goTween();	}, true);}

And I can't understand why in this example "Body" starting move from first position until last tween =/ Just jumping back and only on last tween character move from start to end... 

PS {x, y} are changing every iteration

Link to comment
Share on other sites

I'm not sure exactly what you're trying to do here, but here's how you'd usually use (and stop) a tween:

var sprite = game.add.sprite(0, 0, 'player');game.physics.arcade.enable(sprite, Phaser.Physics.ARCADE);// Stop the physics system trying to move the body, as we'll be moving the sprite manually// via a tween.sprite.body.moves = false;// Add a tween that moves the sprite over 2 seconds - the last 'true' parameter starts the// tween automatically.var tween = game.add.tween(sprite).to({x: 100, y: 100}, 2000, Phaser.Easing.Linear.None, true);tween.onComplete.add(function() {  console.log("This tween has completed!");});// Add a timed event which stops the tween after 1 second - note that doing this will// prevent onComplete firing!game.time.events.add(500, function() {  tween.stop();  console.log("This tween has been stopped prematurely.");}, this);

The problem comes when you start to chain tweens, because then you can't be sure if you have the correct reference to the running tween (as opposed to one that ended and started the next in the chain) so calling stop in that case will probably be trying to stop an already stopped tween! In this case, I've found it easier to use a different tweening system with better support for sequencing, such as GSAP with sequencing being handled very nicely by TimelineLite.

Link to comment
Share on other sites

No problem. If you do continue to use Phaser's tweens, you will have to come up with a way of ensuring you're always referencing the right tween for an object, or using brute-force to stop all of the tweens associated that object using a function like the one I mentioned in this post: http://www.html5gamedevs.com/topic/7332-how-to-stop-moveto/?hl=%2Btweens+%2Bfilter#entry44033

Link to comment
Share on other sites

  • 2 months later...
 Share

  • Recently Browsing   0 members

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