Jump to content

simply click button to restart


crffty
 Share

Recommended Posts

hi.   I'm having a bit of a brain dead moment!!!

I need a super simple if button is clicked restart the game state in the pause menu. (Im using the game pause as a cheat end game screen)

this is the function I'm working on - all I need is to be able to click 'rePlay'.


endGame: function() {

    this.game.paused = true;
    this.game.add.text(this.game.world.centerX - 150, this.game.world.centerY - 100, "game over", { font: "60px Raleway"} );

    // place the reset button
    this.rePlay = game.add.sprite(this.game.world.centerX - 150, this.game.world.centerY + 100, 'rePlay');
    this.rePlay.anchor.setTo(0.5, 0.5);
    
// if replay is pushed --- this 
    if (this.rePlay.event) {
      game.state.start(game.state.current);;
    }

}

 

Link to comment
Share on other sites

I've tried this but its still not doing anything. not even a error. 

 

  endGame: function() {

    this.game.paused = true;
    this.game.add.text(this.game.world.centerX - 150, this.game.world.centerY - 100, "game over", { font: "60px Raleway"} );

    // place the reset button
    this.rePlay = game.add.sprite(this.game.world.centerX - 150, this.game.world.centerY + 100, 'rePlay');
    this.rePlay.anchor.setTo(0.5, 0.5);

    // Enable input on the button...
    this.rePlay.inputEnabled = true;

    // Attach a function to the input down ( click/tap)
    this.rePlay.events.onInputDown.add(function() {
        this.game.state.start('game');
    }, this);

  }

i believe its to do with the game being paused ( pretty sure ) so how do i un-pause the game? 

this.game.paused = false;

doesn't seem to do anything 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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