Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to stop tween in certain cases #1032

Closed
gilangcp opened this issue Jul 16, 2014 · 4 comments
Closed

Failed to stop tween in certain cases #1032

gilangcp opened this issue Jul 16, 2014 · 4 comments

Comments

@gilangcp
Copy link

Hi.

Problem :

Cannot stop tween just after the tween created .

Example case :

Create tween -> suddenly event to stop the tween triggered ( Either by user input / game logic) -> the tween still there .

Example Code :

   var t =  this.game.add.tween(arcASprite).to({ angle: 360 },8000, Phaser.Easing.Linear.None, true, 0 ,Number.MAX_VALUE , false);

t.stop();

Why the problem happened :

it seems that every new tween is added to _add array, processed and moved to another array called _tweens in update method which is processed per frame time. The tween is still in _add array when stop() method called .

Solution :

check _add array for tween in stop() method.

line 40165 ( Phaser 2.0.6)
/**
* Remove a tween from this manager.
*
* @method Phaser.TweenManager#remove
* @param {Phaser.Tween} tween - The tween object you want to remove.
*/
remove: function (tween) {
var i = this._tweens.indexOf(tween);
if (i !== -1) {
this._tweens[i].pendingDelete = true;
} else {
var j = this._add.indexOf(tween);
if (j !== -1) { // <== Add Here
this._add[j].pendingDelete = true;
} // <== Until Here
}
},

Sorry for my bad english , I'm not native english speaker

@photonstorm
Copy link
Collaborator

Thank you for the clear test case.

However could you give me a situation where you would ever create a tween that has autoStart set to true, and then immediately stop it?!

@lucbloom
Copy link
Contributor

Sometimes you create something is a function and you do it a generic way:

     Ship.die = function() {
             this.createDieTween();
             this.dead = true;
             ....
     };

But then you need something special:

     Ship.die = function(cause) {
             this.createDieTween();
             this.dead = true;
             ....
             if (cause === "astroid")
             {
                   this.dieTween.stop(); // Run this animation at a later time, when the Astroid has exploded.
             }
     };

Anyway, it's unexpected behavior.

photonstorm added a commit that referenced this issue Jul 16, 2014
@photonstorm
Copy link
Collaborator

It's a pretty unexpected developer behaviour too.

Anyway, resolved.

@gilangcp
Copy link
Author

Sorry for the late reply , glad that the problem has been resolved., thank you :)

well , in my case :

  1. user click to generate tween
  2. user click again to stop tween
  3. do the step fast enough and you get the behaviour

its something like this (not the actual code):

var sprite = this.game.add(...);
sprite.inputEnabled = true;
sprite.events.onInputDown.add((e) => {
if(e['tween'] == 'undefined'){
e['tween'] = this.game.tween.add(...);
}else{
e['tween'].stop();
delete e['tween'];
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants