-
Notifications
You must be signed in to change notification settings - Fork 4
/
hud.js
41 lines (40 loc) · 1.13 KB
/
hud.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
HUD = function(game) {
this.game = game;
this.score = 0;
this.scoreText = null;
this.gameOverText = null;
};
HUD.prototype = {
create: function() {
localStorage.score = 0;
this.scoreText = this.game.add.text(
this.game.world.width/2,
this.game.world.height/8,
'0',
{
font: '26px "Lucida Console"',
fill: '#fff',
stroke: '#430',
strokeThickness: 4,
align: 'center'
}
);
this.scoreText.anchor.setTo(0.5,0.5);
},
updateScore: function() {
this.score += 1;
this.scoreText.content = this.score;
if(this.game.device.localStorage) {
localStorage.score = this.score;
if (localStorage.highScore) {
if (localStorage.score > localStorage.highScore) {
localStorage.highScore = localStorage.score;
}
}
else {
localStorage.highScore = localStorage.score;
}
}
//else no local storage support
},
};