Do I need to remove a tween on autoComplete()

Hi! My name is daveo
I am writing a very simple Phaser tutorial and I cannot determine if I need to remove a tween after it completes to conserve memory. In my case, I will not need to re-use the tween after it completes… here is my code and I am making an assumption that the tween should be removed on completion:

	whoseTurnIsIt() {
		let x = this.game.config.width / 2;
		let y = this.game.config.height / 2;
		let t = this.whoseTurn = PLAYER_X ? "PLAYER X" : "PLAYER_Y";
		
		let label = this.add.text(x, y, t, 
			{ fontSize: '32px Arial', fill: '#000' });
		label.setOrigin(0.5, 0.5);

		let tween = this.tweens.add({
			targets: label, 
			alpha: 0,
			ease: 'Power1',
			duration: 2000, 
			onComplete: this.turnTweenComplete,
			onCompleteParams: [label]
		});
	}

	turnTweenComplete(tween, targets, params) {
		tween.remove();
	}

Thanks very much!

:wave: No.

Thanks for your answer, samme!
I initially marked it as the ‘solution’ but after thinking about it…

I guess my concern is I am creating a new tween every time I call ‘whoseTurnIsIt()’. This will be called every time a ‘tic tac toe’ square is clicked.
So, if I keep calling ‘this.tweens.add()’ for every click event then won’t it use up memory since the created tween is never removed? Or are you saying it is automatically removed at ‘onComplete()’… because there is also a ‘restart()’

Phaser removes them automatically once complete.

2 Likes

thanks, pal!