Add: ScoreText
This commit is contained in:
@@ -0,0 +1,41 @@
|
|||||||
|
class ScoreText extends Phaser.Text {
|
||||||
|
|
||||||
|
constructor(x, y, score) {
|
||||||
|
super(game, x, y, "+" + score, ScoreText.DEFAULT_TEXT_FONT);
|
||||||
|
|
||||||
|
this.anchor.set(0.5);
|
||||||
|
this.inputEnabled = false;
|
||||||
|
|
||||||
|
var grd = this.context.createLinearGradient(0, 0, 0, this.height);
|
||||||
|
grd.addColorStop(0, '#8ED6FF');
|
||||||
|
grd.addColorStop(1, '#004CB3');
|
||||||
|
this.fill = grd;
|
||||||
|
// this.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
|
||||||
|
this.stroke = '#fff';
|
||||||
|
this.strokeThickness = 5;
|
||||||
|
|
||||||
|
|
||||||
|
let tweenAlpha = game.add.tween(this);
|
||||||
|
tweenAlpha.to( { alpha: 0 }, 1000, Phaser.Easing.Linear.None, true);
|
||||||
|
|
||||||
|
let tweenMoveUp = game.add.tween(this);
|
||||||
|
tweenMoveUp.to( { y: this.y - ScoreText.MOVE_UP_AMOUNT_PX }, 1000, Phaser.Easing.Linear.None, true);
|
||||||
|
tweenMoveUp.onComplete.addOnce(this.destroySelf, this);
|
||||||
|
|
||||||
|
game.add.existing(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
destroySelf() {
|
||||||
|
this.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
ScoreText.DEFAULT_TEXT_FONT = {
|
||||||
|
font: "30px Arial",
|
||||||
|
boundsAlignH: "center", // left, center. right
|
||||||
|
boundsAlignV: "middle", // top, middle, bottom
|
||||||
|
fill: "#fff"
|
||||||
|
};
|
||||||
|
|
||||||
|
ScoreText.MOVE_UP_AMOUNT_PX = 50;
|
||||||
@@ -94,10 +94,10 @@ class Alien extends Phaser.Sprite {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onFired() {
|
onFired() {
|
||||||
this.goRandomPosition();
|
|
||||||
|
|
||||||
if(typeof this.onFiredFunction !== "undefined")
|
if(typeof this.onFiredFunction !== "undefined")
|
||||||
this.onFiredFunction();
|
this.onFiredFunction(this);
|
||||||
|
|
||||||
|
this.goRandomPosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
goRandomPosition() {
|
goRandomPosition() {
|
||||||
|
|||||||
@@ -89,8 +89,10 @@ class Game {
|
|||||||
this.activatedAlienIndex++;
|
this.activatedAlienIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAlienFired() {
|
onAlienFired(sprite) {
|
||||||
console.log("onAlienFired");
|
console.log("onAlienFired");
|
||||||
|
console.log("x : " + sprite.x + ", y : " + sprite.y);
|
||||||
|
let scoreText = new ScoreText(sprite.x, sprite.y, 30);
|
||||||
}
|
}
|
||||||
|
|
||||||
onAlienEscaped() {
|
onAlienEscaped() {
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
<script src="../../game/lib/number_util.js"></script>
|
<script src="../../game/lib/number_util.js"></script>
|
||||||
<script src="../../game/lib/history_record_manager.js"></script>
|
<script src="../../game/lib/history_record_manager.js"></script>
|
||||||
<script src="../../game/lib/input_type_text.js"></script>
|
<script src="../../game/lib/input_type_text.js"></script>
|
||||||
|
<script src="../../game/lib/score_text.js"></script>
|
||||||
<script src="../../game/lib/round_rect_button.js"></script>
|
<script src="../../game/lib/round_rect_button.js"></script>
|
||||||
<script src="../../game/lib/back_button.js"></script>
|
<script src="../../game/lib/back_button.js"></script>
|
||||||
<script src="../../game/lib/fullscreen_button.js"></script>
|
<script src="../../game/lib/fullscreen_button.js"></script>
|
||||||
|
|||||||
Reference in New Issue
Block a user