-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnotification.js
64 lines (47 loc) · 1.76 KB
/
notification.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
60
61
62
63
64
// Used to alert the user of new information
// draw() returns false if the status update is finished
// spec:
// text : text to display
// color : color of text (defaults to black)
// pos : pos of notification
var notification = function(p, spec) {
// object to return
var obj = {};
// --- private variables ---
var time_counter = 0; // used to draw the object at various times
var total_time = 60; // ~ 2 seconds. If changed must be changed in notify in in_game_state to prevent overlap //200; // ~6 secs?
var text_size = 20;
var box_color = spec.color || p.color(255, 255, 255);
// --- public methods ---
obj.draw = function() {
var time_percent = time_counter / total_time;
//var text_size = 25 - 25*(time_percent);
var text_alpha = 255 - 200*time_percent;
//var x_pos = (p.width * (5/8)); //+ (p.width / 2) *time_percent;
//var y_pos = (p.height * (5/8)) - (p.height / 2) *time_percent;
var x_pos = spec.pos.x;
var y_pos = spec.pos.y;
// I don't like the moving from the center
// so I'm trying it stationary
//var x_pos = p.width / 2;
//var y_pos = 70;
// this needs to come before textWidth
p.textAlign(p.CENTER, p.CENTER);
p.textSize(text_size);
var w = p.textWidth(spec.text);
// draw a box behind it
//p.fill(box_color, text_alpha);
//p.rectMode(p.CORNER)
//p.rect(x_pos-w/2-5, y_pos-p.textAscent(), w+10, p.textAscent()*2);
//p.fill(p.color(0, 0, 0), text_alpha);
//p.fill(p.color(255, 255, 255), text_alpha);
p.fill(box_color, text_alpha);
p.text(spec.text, x_pos, y_pos);
if (time_counter > total_time) { // Finished
return false;
}
time_counter++;
return true;
}
return obj;
};