Sign in to follow this  
crffty

simply click button to restart

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

}

 

Share this post


Link to post
Share on other sites
// 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('name of the current state');
}, this);

 

Share this post


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.