Last active
August 29, 2015 14:24
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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