Guest User

Untitled

a guest
Nov 24th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. var highScore = 100; // you would've set this earlier, of course
  2. localStorage.setItem("bunnyDefenderHighScore", highScore); // game-specific key in case you later run another game on the same domain
  3.  
  4. var highScoreToDisplay = 0;
  5. if (localStorage.getItem("bunnyDefenderHighScore") !== null) {
  6. highScoreToDisplay = parseInt(localStorage.getItem("bunnyDefenderHighScore"));
  7. }
  8.  
  9. var gameOverText = this.game.add.text(100, 100, highScoreToDisplay.toString(), {font: "20pt Arial", fill: "#FFFFFF"});
  10.  
  11. var score =0;
  12. var highscore =0;
  13. var highScoreText;
  14. var scoreText;
  15.  
  16. highScoreText = this.game.add.text(600, 40, 'HS: ' + highscore, {
  17. font: '25px Arial',
  18. fill: 'black'
  19. });
  20.  
  21.  
  22. this.score = 0;
  23. this.labelScore = game.add.text(20, 20, "0",
  24. { font: "30px Arial", fill: "black" });
  25.  
  26. highScoreText.text = 'HS: ' + localStorage.getItem("highscore");
  27. {
  28. if (this.score > localStorage.getItem("highscore"))
  29. {
  30. localStorage.setItem("highscore", this.score);
  31. }
  32. }
  33.  
  34. this.score += 1;
  35. this.labelScore.text = this.score;
Add Comment
Please, Sign In to add comment