1

Hi I'm creating a basic game and I need the most simple "PAUSE" menu in the world!!! I am using this:

pauseButton = this.game.add.sprite(10, 10, 'pauseButton');
pauseButton.inputEnabled = true;
pauseButton.events.onInputUp.add(function () {this.game.paused = true;},this);
game.input.onDown.add(function () {if(this.game.paused)this.game.paused = false;},this);
pauseButton.fixedToCamera = true;

I just want to see "Game Paused" when the pause button is pressed that's all! please just tell me the most simple code that will display "game paused" when i click on pause.

Thank you in advance!

Apovtx
  • 185
  • 1
  • 14
gMetrols R
  • 11
  • 2

1 Answers1

1

Something along the lines of this:

var text;

var pauseButton = this.game.add.sprite(10, 10, 'pauseButton');
pauseButton.inputEnabled = true;
pauseButton.events.onInputUp.add(function () {
    this.game.paused = true;
    var style = {fill : '#FFF'};
    text = game.add.text(game.width * 0.5, game.height * 0.5, "Game Over!", style);
    text.anchor.set(0.5, 0.5);
}, this);
game.input.onDown.add(function () {
    if (this.game.paused) {
        this.game.paused = false;
        text.destroy();
    }       
}, this);
pauseButton.fixedToCamera = true;

Added it right in your code, you may want to adjust what is a local variable and what is a field. You can include text properties in the style variable or you can set them later on via text.font, text.fontSize and so on, see the API documentation.

Kamen Minkov
  • 3,324
  • 1
  • 14
  • 21
  • I have tried your code, also played around with it, but the button doesn't work at all now. With my old code, it allows me to pause the game then resume it, I just need it to display text on pause! :( – gMetrols R Oct 14 '15 at 12:09
  • It turns out that I got that if statement wrong. Try it now, or maybe try making the example in Phaser's Sandbox – Kamen Minkov Oct 16 '15 at 07:59