I've been struggling to figure out how to make localStorage save the clicks variable even after refreshing the browser.
Initially, I attempted using JSON.stringify and JSON.parse but later discovered that using parseInt could be a more suitable option since I only need to store a number.
As someone new to programming, I found most examples to be either too complex, poorly explained, or outdated. Hopefully, you can provide some guidance as I've been trying to resolve this issue for over a week now.
For context, I'm working with Phaser 2.5.0 on MAMP with Google Chrome v49.0.2623.112 (64-bit) on OS X 10.8.5.
var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update });
var scoreText;
var clicks = 0;
function preload() {
game.load.image('clickBox', 'assets/ClickMe.png');
game.stage.backgroundColor = '#182d3b';
game.stage.disableVisibilityChange = true;
}
function create() {
localStorage.setItem('clicks', parseInt('clicks'));
localStorage.getItem('clicks');
button = game.add.button(game.width/2, game.height/2, 'clickBox', upScoreText);
scoreText = game.add.text(30, 30, "CLICKS: " + clicks, {font: "20px Arial", fill: "#ffffff", align: "left"});
button.scale.x = 0.5;
button.scale.y = 0.5;
button.anchor.setTo(0.5);
button.inputEnabled = true;
}
function update () {
scoreText.setText("CLICKS: " + clicks);
}
function upScoreText () {
clicks++;
}