TimerText.prototype = Object.create(Phaser.State.prototype);
TimerText.constructor = TimerText;

function TimerText(x, y, fontSize) {
	this.digitText = this.makeTimerText(x, y, fontSize);

	return this;
}


TimerText.prototype.makeTimerText = function(x, y, fontSize) {
	var digitText = game.add.text(x, y, "");
	digitText.anchor.set(1, 0.5);
	digitText.font = "Major Mono Display";	// "VT323";	// "Orbitron";
	digitText.fontSize = fontSize;
	digitText.fontWeight = "bold";	// "normal";
	digitText.style.fill = "white";
	digitText.stroke = "#000000";
	digitText.strokeThickness = 6;
	digitText.text = "00.00";

	return digitText;
}

TimerText.prototype.setText = function(contents) {
	this.digitText.text = contents;
}

TimerText.prototype.setTextColorString = function(colorString) {
	this.digitText.style.fill = colorString;
}

TimerText.prototype.setMSTimeText = function(ms) {
	var sec = Math.floor(ms / 1000);
	var sec2Digit = ("00" + sec).slice(-2);

	var millisec = ms % 1000;
	var millisec2Digit = "" + millisec;
	if(millisec < 10)
		millisec2Digit = ("000" + millisec).substring(0, 2);
	else if(millisec < 100)
		millisec2Digit = ("00" + millisec).substring(0, 2);
	else if(millisec < 10)
		millisec2Digit = ("0" + millisec).substring(0, 2);
	else
		millisec2Digit = ("" + millisec).substring(0, 2);

	this.setText(sec2Digit + "." + millisec2Digit);
}

TimerText.prototype.pad = function (n, width) {
  var n = n + '';
  return n.length >= width ? n : new Array(width - n.length + 1).join('0') + n;
}