Jump to content

Restarting a Game?


rickydamta
 Share

Recommended Posts

http://phaser.io/examples/v2/games/invaders is helpful.

 

Especially

function restart () {    //  A new level starts        //resets the life count    lives.callAll('revive');    //  And brings the aliens back from the dead     aliens.removeAll();    createAliens();    //revives the player    player.revive();    //hides the text    stateText.visible = false;}
Link to comment
Share on other sites

Once the game is instantiated, you can change states. Is it what you are asking for?

 

as an example

 

VohoGame.game = new Phaser.Game(VohoGame.gameOptions.gameWidth, VohoGame.gameOptions.gameHeight, Phaser.CANVAS, "gamecanvas");

 

VohoGame.game.state.add("Boot", VohoGame.Boot);
VohoGame.game.state.add("Preload", VohoGame.Preload);
VohoGame.game.state.add("GameTitle", VohoGame.GameTitle);
VohoGame.game.state.add("GameStart", VohoGame.GameStart);
VohoGame.game.state.add("GameOver", VohoGame.GameOver);
VohoGame.game.state.add("GameSuccess", VohoGame.GameSuccess);
/* Start the game with Boot state */
VohoGame.game.state.start("Boot");
Link to comment
Share on other sites

Are you talking about restarting a level? Like if you die it resets the level? If you are using states you can do something like

 

// In update

this.game.physics.collide.(this.enemy, this.player, this.killPlayer, null, this)

 

if (this.enemy && this.player.collide) {

         this.killPlayer();

},

 

// In game state

killPlayer: function() {

this.player.kill();

 

game.state.start('Game');

};

 

Not sure if this is what you are asking but in this case if a player and enemy collide it kills the player and restarts the 'Game' State. This is if you are using states.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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