Add: CountDownText
This commit is contained in:
@@ -4,7 +4,7 @@ ComboText.constructor = ComboText;
|
||||
function ComboText() {
|
||||
Phaser.Text.call(
|
||||
this, game,
|
||||
game.world.width / 2,
|
||||
game.world.centerX,
|
||||
ComboText.TEXT_POS_Y,
|
||||
"",
|
||||
ComboText.DEFAULT_TEXT_FONT
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
Usage:
|
||||
|
||||
var countDownText = new CountDownText(
|
||||
(function() {this.startGame();}).bind(this)
|
||||
);
|
||||
countDownText.startCountDown();
|
||||
|
||||
*/
|
||||
|
||||
CountDownText.prototype = Object.create(Phaser.Text.prototype);
|
||||
CountDownText.constructor = CountDownText;
|
||||
|
||||
function CountDownText(onStartEventHandler) {
|
||||
this.onStart = onStartEventHandler;
|
||||
|
||||
this.countDownNumber = 3;
|
||||
if(isDebugMode())
|
||||
this.countDownNumber = 1;
|
||||
|
||||
Phaser.Text.call(
|
||||
this, game,
|
||||
game.world.centerX,
|
||||
game.world.centerY,
|
||||
"",
|
||||
CountDownText.DEFAULT_TEXT_FONT
|
||||
);
|
||||
|
||||
this.anchor.set(0.5);
|
||||
this.inputEnabled = false;
|
||||
|
||||
this.stroke = '##333';
|
||||
this.strokeThickness = 50;
|
||||
|
||||
game.add.existing(this);
|
||||
|
||||
this.hide();
|
||||
};
|
||||
|
||||
CountDownText.prototype.setCountDownNumber = function(startNumber) {
|
||||
this.countDownNumber = startNumber;
|
||||
}
|
||||
|
||||
CountDownText.prototype.startCountDown = function(comboCount, comboBonus) {
|
||||
this.countDown();
|
||||
}
|
||||
|
||||
CountDownText.prototype.fadeOut = function(comboCount) {
|
||||
this.tweenFade = game.add.tween(this);
|
||||
this.tweenFade.to({alpha:0}, CountDownText.TWEEN_FADE_OUT_TIME, Phaser.Easing.Quadratic.In, true, 0);
|
||||
this.tweenFade.onComplete.add(this.hide, this);
|
||||
this.tweenFade.start();
|
||||
}
|
||||
|
||||
|
||||
CountDownText.prototype.countDown = function(comboCount) {
|
||||
if(this.countDownNumber == 0) {
|
||||
if(this.onStart != null)
|
||||
this.onStart();
|
||||
return;
|
||||
}
|
||||
|
||||
this.text = this.countDownNumber.toString();
|
||||
this.countDownNumber--;
|
||||
|
||||
this.tweenCountDown();
|
||||
}
|
||||
|
||||
|
||||
CountDownText.prototype.tweenCountDown = function() {
|
||||
this.alpha = 1;
|
||||
|
||||
var countDownTween = game.add.tween(this);
|
||||
countDownTween.to( { alpha: 0 }, CountDownText.TWEEN_FADE_OUT_TIME, Phaser.Easing.Linear.None, true);
|
||||
countDownTween.onComplete.add(this.countDown, this);
|
||||
}
|
||||
|
||||
CountDownText.prototype.hide = function() {
|
||||
this.alpha = 0;
|
||||
this.scale.set(1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
CountDownText.DEFAULT_TEXT_FONT = {
|
||||
font: "bold 200px Arial",
|
||||
fill: "#fff",
|
||||
boundsAlignH: "center",
|
||||
boundsAlignV: "middle"
|
||||
};
|
||||
|
||||
CountDownText.TWEEN_FADE_OUT_TIME = 1000;
|
||||
Reference in New Issue
Block a user