Jump to content

Pause text problems


edanfersi
 Share

Recommended Posts

Hi guys.

 

I´m starting a project and I tried creating a text to let me resume the game and It doesn´t work. Can you help me with this please?  :( .

 

This is a function I made to pause the game:

 

pauseFunction: function(){

    if (game.paused == false){
        pausa = game.add.sprite(0, 0, 'Pausa');
        pausa.alpha=0.7;
       
        pause_label_screen = game.add.text(350,150,'PAUSE',{ fill: '#fff' });
        pause_label_screen.font = 'Press Start 2P';
        pause_label_screen.fontSize = 20;
       
        continue_text = game.add.text(350,350,'CONTINUE',{ fill: '#fff' });
        continue_text.font = 'Press Start 2P';
        continue_text.fontSize = 12;
        continue_text.inputEnabled = true;
        continue_text.events.onInputDown.add(function() {
            pausa.destroy();
            pause_label_screen.destroy()
            game.paused = false;

        },this);

        game.paused = true;
     }

     else if(game.paused == true){
            this.unpauseFunction();
    }
},

 

 

and this is the unpause function:

 

unpauseFunction: function(){

    continue_text.destroy();
    pausa.destroy();
    pause_label_screen.destroy()
    game.paused = false;
},

 

 
 
Link to comment
Share on other sites

What is the problem you are having?  Is it just that the text stays on screen?


You seem to have two unpause sections, one in 'unpauseFunction' and the other in the input handler for continue_text.  I notice that the latter one doesn't destroy continue_text.  Perhaps making the input handler call unpauseFunction would work (or have you linked unpauseFunction into phaser to be called automatically when the game is unpaused?  That might cause errors when the event handler has already destroyed some of the things it is expecting)
Link to comment
Share on other sites

  • 3 weeks later...

The way I understand it, is that setting the Phaser.game.paused property to true will essentially freeze the entire game. It still responds to window.onkeydown event (according to this post) but it won't respond to clicks or onDowns on any Phaser classes like text or button etc. However, when you want to run your game on a touch device you need the Phaser.button or Phaser.text for user input..  :(

 

So the way i did it is just make my own global MyGameIsPaused variable which I set to true or false with a my pause button, and then put something like the code below in any of my update functions

update: function(){    if (MyGameIsPaused == false) {        // my game update code    };}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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