Jump to content

looping tween are not removed from TweenManager


bilboon
 Share

Recommended Posts

Hi all,

 

Am i wrong or is it a bug ? 

var game = new Phaser.Game(500, 500, Phaser.AUTO, 'game', {        create: create,        update: update});var t1;function create(){    var g = game.add.graphics();    g.beginFill(0xFFFFFF, 0.5);    g.drawRect(0, 0, 200, 200);    t1 = game.add.tween(g);    t1.to({ alpha: 0.1 }, 1000, null).to({ alpha: 0.5 }, 1000, null).loop();    t1.start();    t1.stop();}function update(){    console.log(t1._manager._tweens.length);    // log: 1, should be 0 ?}

Thx.

Link to comment
Share on other sites

If I try to destroy a sprite that is tweening, within a group, it logs an error :

 

"SCRIPT5007: Unable to get property 'length' of undefined or null reference 

phaser.min.js, line 4 character 26137"
 
Likely todo with this code:
 
for(var a=this._bindings.length;a--;)this._bindings[a]._destroy();
 
Maybe this is part of the problem you are talking about...
 
The only way I got passed my issue, was by removing it from group.
Link to comment
Share on other sites

  • 1 month later...

Hi, i've finally found time to investigate a bit.

 

"Tween.to" is creating a second tween which is chained to previous tween so  :

t1.to(...).to(...).loop()

This creates two chained tweens : t1 -> t2 -> t1 -> ...

Only one of this tween is runned by manager at a time.

 

The problem is that when we call t1.stop() and t1 is not scheduled in manager (because t2 is running), the manager is not marking it to pendingDelete, and t1 is restarted per t2 when finishing and tweens are looping infinitely.

 

I fixed the bug modifying Tween.stop:

 /**    * Stops the tween if running and removes it from the TweenManager. If there are any onComplete callbacks or events they are not dispatched.    *    * @method Phaser.Tween#stop    * @return {Phaser.Tween} Itself.    */    stop: function () {        this.isRunning = false;        this.pendingDelete = true; // always force pendingDelete        this._manager.remove(this);        return this;    },

Not sure if there's no border effect.

Link to comment
Share on other sites

  • 1 month later...

I can confirm the same effect was happening when trying to stop a loop tween.  I was creating an auto-starting loop tween on a sprite's onInputDown and stopping it in it's onInputUp.  The tween just scaled the sprite smaller then back to normal and so on.  If the onInputUp fired whilst the second tween was in operation the sprite would continue looping forever.  If I clicked again I'd get multiple loop tweens applied with jittery effects when one battled with another to change the scale.

 

Tried the change and all appears to be good to me.

Link to comment
Share on other sites

  • 5 months later...

Hi there. 
Bilboon method is fine! all you want to do. is to add it to a new function. so it will be no effect on phaser original methods. 
And also it will give you the ability to choose between the original logic. and between the new logic. 

 

    /** Phaser 2.0.7     * Force Stop added to force stop the tween! by: acca [Peter.Fenyvesi]     */    forceStop: function()    {        this.isRunning = false;        this.pendingDelete = true; // always force pendingDelete        this._manager.remove(this);        return this;      },
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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