-
Notifications
You must be signed in to change notification settings - Fork 2
/
Text.java
34 lines (30 loc) · 896 Bytes
/
Text.java
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
import java.awt.*;
public class Text {
private double x;
private double y;
private long time, start;
private String s;
public Text (double x, double y, long time, String s) {
this.x = x;
this.y = y;
this.time = time;
this.s = s;
start = System.nanoTime();
//start = (System.nanoTime() - start) / 1000000;
}
public boolean update () {
long elapsed = (System.nanoTime() - start) / 1000000;
if (elapsed > time)
return true;
return false;
}
public void draw (Graphics2D g) {
g.setFont(new Font("Century Gothic", Font.PLAIN, 12));
long elapsed = (System.nanoTime() - start) / 1000000;
//int alpha = (int) (255 * Math.sin(Math.PI * elapsed / time));
//if (alpha > 255) alpha = 255;
g.setColor(new Color(255, 255, 255, 128));
int length = (int) g.getFontMetrics().getStringBounds(s, g).getWidth();
g.drawString(s, (int) (x - (length / 2)), (int) y);
}
}