grammka Posted July 1, 2014 Share Posted July 1, 2014 Its cry 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 More sharing options...
lewster32 Posted July 1, 2014 Share Posted July 1, 2014 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. grammka 1 Link to comment Share on other sites More sharing options...
grammka Posted July 1, 2014 Author Share Posted July 1, 2014 Thank u again, lewster32 Link to comment Share on other sites More sharing options...
lewster32 Posted July 1, 2014 Share Posted July 1, 2014 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 More sharing options...
PadreMontoya Posted September 21, 2014 Share Posted September 21, 2014 I hit a similar issue. Ultimately I had to go into the sprite's tween manager and stop each individual tween. This worked for me:tween.stop();for (var i in tween._manager._tweens){ tween._manager._tweens[i].stop();} Link to comment Share on other sites More sharing options...
Recommended Posts