caa-game/src/helpers/textbox.js

34 lines
759 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(string, lifespan) {
super();
this.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 = { x: 0, y: 0 };
this.add(background);
const text = new Text(string, fillStyle);
text.pos = { x: 8, y: 18 };
this.add(text);
}
update(dt) {
super.update(dt);
if (this.lifespan <= 0) {
this.dead = true;
} else {
this.lifespan -= dt;
}
}
}
module.exports = TextBox;