36 lines
834 B
JavaScript
36 lines
834 B
JavaScript
var asdf = require("asdf-games");
|
|
// eslint-disable-next-line no-unused-vars
|
|
const { Container, Text, Rect } = asdf;
|
|
|
|
const fillStyle = {fill: "#ffffff", font: "16px Minecraft"};
|
|
|
|
class TextBox extends Container {
|
|
constructor(pos, string, lifespan) {
|
|
super();
|
|
this.pos = pos !== undefined ? pos : { x: 0, y: 0 };
|
|
this.string = string;
|
|
this.lifespan = lifespan;
|
|
|
|
const background = new Rect(640, 24, {fill: "rgba(0,0,0,0.5)"});
|
|
background.pos = this.pos;
|
|
this.add(background);
|
|
|
|
const text = new Text(string, fillStyle);
|
|
text.pos = { x: this.pos.x + 8, y: this.pos.y + 18 };
|
|
this.add(text);
|
|
|
|
console.log(this);
|
|
}
|
|
|
|
update(dt) {
|
|
super.update(dt);
|
|
|
|
if (this.lifespan <= 0) {
|
|
this.dead = true;
|
|
} else {
|
|
this.lifespan -= dt;
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = TextBox; |