-
Notifications
You must be signed in to change notification settings - Fork 3
/
label.js
59 lines (38 loc) · 1.06 KB
/
label.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Label {
constructor(x, y, text) {
this.x = x;
this.y = y;
this.width = 60;
this.height = 20;
this.velX = 0;
this.velY = 0;
this.text = text;
this.life = 100;
}
step(dt) {
this.velY -= gravity;
// apply forces
this.x += dt * this.velX;
this.y += dt * this.velY;
this.life -= 3;
}
draw(ctx) {
ctx.save();
ctx.translate(this.x, this.y-120);
// if (game.debug) {
// ctx.beginPath(),
// ctx.rect(-this.width / 2, -this.height / 2, this.width, this.height);
// ctx.stroke();
// }
ctx.beginPath();
ctx.strokeStyle = "black";
ctx.font = "bold 26px Helvetica";
ctx.fillText( this.text, 0-this.width / 2, 0+this.height / 2);
ctx.stroke();
ctx.font = "bold 26px Helvetica";
ctx.fillStyle = "yellow";
ctx.fillText( this.text, -3-this.width / 2, -2+this.height / 2);
ctx.stroke();
ctx.restore();
}
}