-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.js
More file actions
45 lines (35 loc) · 876 Bytes
/
Copy pathtimer.js
File metadata and controls
45 lines (35 loc) · 876 Bytes
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
var Timer = function(game, refreshInt, ph) {
this.game = game;
this.text = ph;
this.refreshInt = refreshInt;
this.gameTimer = game.time.events.loop(refreshInt, function(){
this.updateTimer();
}, this);
};
Timer.prototype.constructor = Timer;
Timer.prototype.updateTimer = function(){
if(!this.totalTime)
{
return;
}
//Time elapsed in seconds
this.timeElapsed += this.refreshInt / 1000;
//Time remaining in seconds
var timeRemaining = this.totalTime - this.timeElapsed;
if(this.text != null)
this.text.text = timeRemaining + " sec";
if(timeRemaining <= 0)
{
this.end = true;
}
}
Timer.prototype.start = function(limit)
{
this.totalTime = limit;
this.timeElapsed = 0;
this.end = false;
}
Timer.prototype.isOver = function(limit)
{
return this.end;
}