Scene.time.paused does not work

Hi,

i want to add a Clock to my game, which Shows the time you spend for a level.
But while you answering a question, the timer should be paused.

So i tried like this:

update() {
	var timer = this.time.now - 10000;
	timeText.x = this.cameras.main.scrollX + 16;
	timeText.setText("Zeit: " + Phaser.Math.RoundTo(timer/1000, 0) + " Sek.");
	// show minutes after 60 seconds
	if(Phaser.Math.RoundTo(timer/1000 >= 60)) {
		timeText.setText("Zeit: " + Phaser.Math.RoundTo(timer/60000, -2) + " Min.");
	};
	//pause timer while quiz is visible
	if(quiz.visible){
		this.time.paused = true; 
	} else {
		this.time.paused = false;
		}
}

The timer works fine but i doesn’t stop counting while quiz is visible whether the bool of this.time.paused is true at this moment.
What am I doing wrong?

Thanks a lot!

I would use a timer event for this.

var timer = this.time.addEvent({ delay: 999999 });

timer.getElapsedSeconds();
timer.paused = true;

Thanks for your advice but I’m still having trouble getting the right value.

So i added in my update-function:

var timer = this.time.addEvent({ delay: 999999 });

console.log(timer);
console.log("timer.getElapsed(): " + timer.getElapsed(),"timer.getElapsedSeconds(): " + timer.getElapsedSeconds());
console.log("timer.elapsed: " + timer.elapsed);

And the result is:
timer

So why, if the value of my TimerEvent is 183.76 it returns 0 for every request?

Hello, create the timer event in the create function and use it whereever…
Here it is an example with timer event and pause:

http://labs.phaser.io/view.html?src=src\time\pause%20and%20resume.js

I hope it helps to understand

Create the timer just once, then read elapsed time in update().