-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.js
73 lines (65 loc) · 1.5 KB
/
timer.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
65
66
67
68
69
70
71
72
73
/*
* GDevelop JS Platform
* Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
*/
/**
* Represents a timer, which must be updated manually with {@link gdjs.Timer#updateTime}.
*
* @class Timer
* @memberof gdjs
* @param {string} name The name of the timer.
*/
gdjs.Timer = function(name)
{
this._name = name;
this._time = 0;
this._paused = false;
}
/**
* Get the name of the timer
* @return {string} The name of the timer
*/
gdjs.Timer.prototype.getName = function() {
return this._name;
}
/**
* Get the time of the timer, in milliseconds.
* @return {number} The time of the timer, in milliseconds.
*/
gdjs.Timer.prototype.getTime = function() {
return this._time;
}
/**
* Notify the timer that some time has passed.
* @param {number} time The elapsed time, in milliseconds.
*/
gdjs.Timer.prototype.updateTime = function(time) {
if ( !this._paused ) this._time += time;
}
/**
* Change the time.
* @param {number} time The new time, in milliseconds.
*/
gdjs.Timer.prototype.setTime = function(time) {
this._time = time;
}
/**
* Reset the time to zero.
*/
gdjs.Timer.prototype.reset = function() {
this.setTime(0);
}
/**
* Set if the timer is paused.
* @param {boolean} enable true to pause the timer, false otherwise.
*/
gdjs.Timer.prototype.setPaused = function(enable) {
this._paused = enable;
}
/**
* Check if the timer is paused.
*/
gdjs.Timer.prototype.isPaused = function() {
return this._paused;
}