Add: show heart_full, heart_empty
This commit is contained in:
+38
-12
@@ -2,21 +2,47 @@ class HeartGauge {
|
||||
|
||||
constructor(heartManager) {
|
||||
this.heartManager = heartManager;
|
||||
this.hearts = [];
|
||||
|
||||
this.heartManager.addOnChangeHeartListener(
|
||||
() => {
|
||||
console.log(this.heartManager.getHearts());
|
||||
}
|
||||
this.heartManager.addOnChangeCountListener(
|
||||
() => { this.onChangeCountListener(); }
|
||||
);
|
||||
|
||||
this.heartManager.addOnChangeMaxCountListener(
|
||||
() => { this.onChangeMaxCountListener(); }
|
||||
);
|
||||
|
||||
let startPosX = 950;
|
||||
let posY = 30;
|
||||
for(let i = 0; i < HeartManager.HEART_MAX_COUNT; i++) {
|
||||
let heart = game.add.sprite(startPosX - i * 30, posY, "heart_full");
|
||||
heart.anchor.set(0.5);
|
||||
heart.scale.set(1);
|
||||
heart.alpha = 0;
|
||||
this.hearts.push(heart);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
onChangeCountListener() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
HeartGauge.DEFAULT_TEXT_FONT = {
|
||||
font: "30px Arial",
|
||||
boundsAlignH: "center", // left, center. right
|
||||
boundsAlignV: "middle", // top, middle, bottom
|
||||
fill: "#fff"
|
||||
};
|
||||
onChangeMaxCountListener() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
HeartGauge.MOVE_UP_AMOUNT_PX = 50;
|
||||
start() {
|
||||
this.updateHearts();
|
||||
}
|
||||
|
||||
updateHearts() {
|
||||
for(let i = 0; i < this.heartManager.getMaxCount(); i++) {
|
||||
if(i < this.heartManager.getCount())
|
||||
this.hearts[i].loadTexture("heart_full");
|
||||
else
|
||||
this.hearts[i].loadTexture("heart_empty");
|
||||
|
||||
this.hearts[i].alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user