rickydamta

Restarting a Game?

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;}

Share this post


Link to post
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");

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.