Jump to content

tweens.remove() does not work in Phaser 2.0.4


Dev Monster
 Share

Recommended Posts

I have been trying to remove the tweens that were added in the states of my game but they do not get removed and cause the game to start chugging after a few plays. When the user replays the game, old tweens are still hanging around and are doubling each time a new game is played. I have tried every method on this forum but nothing is working.

I add several tweens during each state to animate in objects to the screen like so: playButtonTween = this.game.add.tween(playButton).to({x: 390, alpha:1}, 1500, Phaser.Easing.Quintic.Out, true, 0, false);

I have a function called shutdown (reserved function in Phaser) that I call before my game transitions from one state to another (i.e. Menu ==> Instructions). In this function I have tried to remove the tweens but when I console.log the this.tweens on shutdown, I am still seeing the tween objects listed.

I am able to get all the tweens by calling game.tweens.getAll().I try to remove all the tweens in the state by calling game.tweens.removeAll(), but after console.logging game.tweens they are still there.

shutDown: function ()
{
        console.log("game.tweens getALL before: "+ game.tweens.getAll());

        game.tweens.removeAll();
        
        console.log("game.tweens getALL after: "+ game.tweens.getAll());
}

This is logged when I leave the Menu state the first time:

game.tweens getALL before: [object Object],[object Object],[object Object],[object Object]
game.tweens getALL after: [object Object],[object Object],[object Object],[object Object]

This is logged when I leave the Menu state the second time:

game.tweens getALL before: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
game.tweens getALL after: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

This is logged when I leave the Menu state the third time:

game.tweens getALL before: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
game.tweens getALL after: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

As you can see, the tween objects never get deleted and keep getting added.

// I have tried other suggestions on this forum using methods from the previous builds of Phaser but none of them work either:
this.game.tweens.remove(tweenName);
this.tweens.remove(tweenName);

this.tweens.removeAll();

 

// I tried using the code below but it does nothing:

playButtonTween.isRunning = false;
playButtonTween.pendingDelete = true; // always force pendingDelete
this.game.tweens.remove(playButtonTween);

// I've tried to destroy tween (this works to stop the tween and set it to null, but its still in the this.tweens list)
if (this.playButtonTween)
{
     this.playButtonTween.onComplete.removeAll();
     this.playButtonTween.stop();
     this.playButtonTween = null;
}

Rich suggested: “Keep a reference to the tweens you create and then game.tween.remove() them.” I do that and have no problem accessing the tween list. But game.tweens.remove(tweenName) and game.tweens.removeAll() do not work for me.

 

Please help! This is slowing down and eventually killing my game play because nothing is getting cleared out.

 

Thanks!

Link to comment
Share on other sites

I was finally able to solve the issue by doing the following in my shutDown function:

 

this.tweens = [];

 

I just reset the array to an empty array and all Objects disappeared in the console.log. The game no longer chugs and everything is running smoothly.

 

I tried everything else and no other methods worked. Here is my shutDown function:

shutDown: function () {        // emptys out the tweens array so Objects dont build up	this.tweens = [];		// after cleaning, go to next state	this.loadHowToScreen();},
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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