-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTimer.js
43 lines (38 loc) · 1.13 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
Timer = function(gameState){
this.gameState = gameState;
};
Timer.prototype = {
counter: 0,
started: false,
preload: function(){
this.gameState.load.spritesheet('time-background', 'assets/time-background.png');
},
create: function(){
this.background = this.gameState.add.sprite(0, game.height - 60, 'time-background');
this.background.scale.x = this.background.scale.y = 0.4;
this.counterText = this.gameState.add.text(45, game.height - 49, '0.0', {
font: "26px Verdana",
fill: "#fff",
align: "center"
});
// The texts position is relative to the cameras.
this.counterText.fixedToCamera = this.background.fixedToCamera = true;
this.gameState.time.events.loop(100, this.updateCounter, this);
},
updateCounter: function() {
if(this.started) {
this.counter++;
if(this.counter % 10 === 0){
this.counterText.setText(this.counter / 10 + ".0");
if(this.counter === 100)
this.counterText.cameraOffset.x = 38;
else if(this.counter === 1000)
this.counterText.cameraOffset.x = 30;
}
else {
this.counterText.setText(this.counter / 10);
finishedLevelTime = this.counter / 10;
}
}
}
};