-
Notifications
You must be signed in to change notification settings - Fork 0
/
staticSentence.js
53 lines (40 loc) · 1.53 KB
/
staticSentence.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
/*
* Reference: https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API/Tutorial/Basic_animations
*/
class staticSentence extends sentence {
constructor(canvas, Y) {
// Base constructor call
super(canvas);
// Variables specific of this type of sentence
this.X = null;
this.Yoriginal = Y; // Drawing start position to have the sentence centered on Y
this.time;
this.interval;
this.size = 25;
this.offesetAmount = Math.round(this.size + (this.size / 3));
this.requestSentence(); // Begin
}
draw(deltaT) {
var elapsed = (new Date).getTime() - this.time;
this.fade = (elapsed < this.interval * 0.8) ? true : false;
/*
If time is elapsed,
Not if already requested.
If we had some error wait a little bit before retring.
This also manages disconnections.
*/
this.refresh = elapsed > this.interval ? true : false;
super.draw(deltaT);
}
// Compute all the parameters from the sentence we just got
createNew() {
// Creation and expiration times
this.time = (new Date).getTime();
this.interval = 10000; // + Math.random() * 2000;
// Split into lines
super.createNew();
// Vertical (Y) position, offeset for drawing taking into account
// the number of lines, the size and the space between lines
this.Y = this.Yoriginal - ((this.line.length * this.offesetAmount - this.offesetAmount) / 2);
}
}