From 59b2a3ee677a06de263ebb2a3de0655999922983 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=A2=E1=84=91=E1=85=B3=E1=86=AF=20=E1=84=82?= =?UTF-8?q?=E1=85=A9=E1=84=90=E1=85=B3=E1=84=87=E1=85=AE=E1=86=A8?= Date: Tue, 29 Jan 2019 22:29:18 +0900 Subject: [PATCH] Add: CountDownText --- src/game/lib/text/combo_text.js | 2 +- src/game/lib/text/count_down_text.js | 92 ++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 src/game/lib/text/count_down_text.js diff --git a/src/game/lib/text/combo_text.js b/src/game/lib/text/combo_text.js index 4e59ee3..c20b083 100644 --- a/src/game/lib/text/combo_text.js +++ b/src/game/lib/text/combo_text.js @@ -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 diff --git a/src/game/lib/text/count_down_text.js b/src/game/lib/text/count_down_text.js new file mode 100644 index 0000000..81b18af --- /dev/null +++ b/src/game/lib/text/count_down_text.js @@ -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; \ No newline at end of file