purpleyams4ever Posted May 3, 2017 Share Posted May 3, 2017 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; //text this.scoreText=game.add.text(game.world.centerX+125, 100, "0"); this.scoreText.fill="#ffff00"; 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.fill="#ffff00"; 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") { return; } this.map.removeTile(tile.x, tile.y, this.layer); score++; this.scoreText.text = score; gameMedia.playSound(this.collectSound); if (score == 4) { gameMedia.playSound(this.victoryMusic); game.state.start("StateVictory"); } } Everything else works just fine except for this and I'm super-stumped. Thanks heaps in advance!!!! Link to comment Share on other sites More sharing options...
samme Posted May 3, 2017 Share Posted May 3, 2017 What happens in "Play Again"? Link to comment Share on other sites More sharing options...
purpleyams4ever Posted May 4, 2017 Author Share Posted May 4, 2017 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); console.log(this); this.btnPlayAgain = gameButtons.addButton("playAgain", -1, -1, this.playAgain, this); } , playAgain: function () { game.state.start("StateMain"); } Link to comment Share on other sites More sharing options...
RubbleGames Posted May 4, 2017 Share Posted May 4, 2017 Have you tried using the console to see if the text still exists when it's not displaying? I've come across something similar and it turned out my sprites were displaying off screen. Link to comment Share on other sites More sharing options...
purpleyams4ever Posted May 4, 2017 Author Share Posted May 4, 2017 3 hours ago, RubbleGames said: Have you tried using the console to see if the text still exists when it's not displaying? I've come across something similar and it turned out my sprites were displaying off screen. Hi RubbleGames, I'll def try this! Link to comment Share on other sites More sharing options...
purpleyams4ever Posted May 4, 2017 Author Share Posted May 4, 2017 Found this post which might be helpful (posting it here for anyone else who might have this problem). Going to test it out and keep everyone updated! http://www.html5gamedevs.com/topic/18068-text-not-showing-on-state-change/ Link to comment Share on other sites More sharing options...
Recommended Posts