Skip to content

Instantly share code, notes, and snippets.

@zackproser
Last active August 29, 2015 14:24
Show Gist options
  • Save zackproser/15c49f04bd76bf4e2d22 to your computer and use it in GitHub Desktop.
Save zackproser/15c49f04bd76bf4e2d22 to your computer and use it in GitHub Desktop.
A demonstration of how to handle game state transitions within a Phaser HTML5 level
handleUserDataGameLoss: function() {
//Handle Player Scores and Times
this.interval = 0;
this.step = this.playerStats.topScore - this.interval;
if (this.score > this.step) {
this.playerStats.topScore = this.interval + this.score;
}
this.playerStats.topTime = this.playerStats.topTime + this.survivalTimer.seconds;
localStorage.setItem('Canyon_Runner_9282733_playerStats', JSON.stringify(this.playerStats));
//Reset Game After Pause
this.resetTimer = this.game.time.create(this.game);
this.resetTimer.add(4000, function(){
this.explosion.kill();
this.game.state.start('MainMenu');
}, this);
this.resetTimer.start();
},
handleUserDataLevelComplete: function() {
//Handle Player Scores and Times
this.playerStats.topScore = 50;
this.playerStats.topTime = this.playerStats.topTime + this.survivalTimer.seconds;
//Set Highest Level Completed by Player
this.playerStats.returnPlayerToState = 'NavigationBandit';
localStorage.setItem('Canyon_Runner_9282733_playerStats', JSON.stringify(this.playerStats));
this.buttonAdvance = this.game.add.button(350, 500, 'sprites', this.nextLevel, this, 'advance-button', 'advance-button', 'advance-button');
this.buttonAdvance.fixedToCamera = true;
},
nextLevel: function() {
this.sound.stop('success');
this.state.start('NavigationBandit');
},
quitGame: function (pointer) {
this.state.start('MainMenu');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment