Dev Monster Posted May 29, 2014 Share Posted May 29, 2014 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 pendingDeletethis.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 More sharing options...
j0hnskot Posted May 29, 2014 Share Posted May 29, 2014 Can you change the way to output the comments? Do something like console.log("game.tweens getALL before: ");console.log(game.tweens.getAll());That way you will see what each object contains. Tell us what the output is. Link to comment Share on other sites More sharing options...
Dev Monster Posted May 29, 2014 Author Share Posted May 29, 2014 Hi j0hnskot, Im getting the same thing only all of the object information is showing. What should I look for inside the object? Thanks for the help! game.tweens getALL before: [Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object=[{Point (x=0.5 y=0.5)}], game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}] game.tweens getALL before: [Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object=[{Point (x=0.5 y=0.5)}], game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}, Object { _object={...}, game={...}, _manager={...}, more...}] Link to comment Share on other sites More sharing options...
wayfinder Posted May 30, 2014 Share Posted May 30, 2014 You could iterate through your tweens and call stop() on each of them... Link to comment Share on other sites More sharing options...
Dev Monster Posted May 31, 2014 Author Share Posted May 31, 2014 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 More sharing options...
Recommended Posts