Jump to content

Score disappears on reload


Recommended Posts

Hi Everyone,

My score disappears every time I restart the game (AND IT'S DRIVING ME INSAAAAAAAAAANE). If I completely reload the server, it reappears at the top of the game where it should be. If I click the "Play Again" button from Game Over screen, my game loads again, sans "Score." Any insights as to how I can correct this problem would be greatly appreciated. Here is The Code:

in main.js (where all my globals live)

var score  = 0;

In StateMain.js under the create:function I have:

create: function () {
        score = 0;

        this.scoreText=game.add.text(game.world.centerX+125, 100, "0");
        this.scoreText.fontSize = 55;
        this.scoreText.anchor.set(0.5, 0.5);
        this.scoreText.fixedToCamera = true;

        this.scoreLabel=game.add.text(game.world.centerX, 100, "Score: ");
        this.scoreLabel.fontSize = 55;
        this.scoreLabel.anchor.set(0.5, 0.5);
        this.scoreLabel.fixedToCamera = true;


And here's my code for the incrementation:

 gotBomb: function (sprite, tile) {
        if (sprite.name == "monster") {
        this.map.removeTile(tile.x, tile.y, this.layer);
        this.scoreText.text = score;

        if (score == 4) {


Everything else works just fine except for this and I'm super-stumped. Thanks heaps in advance!!!!

Link to comment
Share on other sites

4 hours ago, samme said:

What happens in "Play Again"?

Hi Samme,

If I click the "Play Again" button, my game loads again from the beginning, just without the score (please see the first image). If I restart the server entirely, the score appears and increments just fine. 

Here is my "Play Again" function inside of StateOver.js:

create: function () {

        var overText = game.add.text(game.width / 2, game.height / 2 - 100, "Game Over");
        overText.fill = "#ffffff";
        overText.anchor.set(0.5, 0.5);

        this.btnPlayAgain = gameButtons.addButton("playAgain", -1, -1, this.playAgain, this);

    , playAgain: function () {


Screen Shot 2017-05-03 at 8.52.34 PM.png

Screen Shot 2017-05-03 at 8.53.28 PM.png

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...