Jump to content

Paused/Unpause issue


Heppell08
 Share

Recommended Posts

I've been receiving feedback about my game and been asked that a pause button would be useful to the game. I've used paused in the past with an onDown keyboard function but that will not apply to my current game as the game has both touchscreen and desktop compatibility. Having an onDown key function that works on desktop but not mobile phone is useless so an all round way of doing it was an onscreen button.

~Click button, pause game.

 

~Click button, unpause game.

 

Sounds unbelievably easy i know, but for some reason i just cant unpause the game. I've looked at timers and other stuff but the whole loop stops dead in its tracks.

Is there not a way to have something ticking for the purpose of unpausing?

 

Heres my pause code as it is at the minute and not working...

            pauseGame: function(pointer)            {                gamePaused.visible = false;                unPause.visible = true;                this.game.paused = true;            },            unPauseGame: function()            {                this.game.paused = false;                unPause.visible = false;                gamePaused.visible = true;            }, 

I was toying with the idea of hiding a button and showing an exact copy of the same button but with the ability to unpause the game. 

I also looked at other ways but seem to not be able to get this to work in anyway.

 

Link to comment
Share on other sites

I think that there isn't a way in Phaser to do this because all the loops get cancelled, the button will never know if it is pressed because it isn't checked anymore.

Maybe you can create an extra loop yourself in which you check if the game is paused and if there is a touch event on the location of the button and then unpause the game.

Link to comment
Share on other sites

Yeah just going to pause the main parts of the game within the boolean and have an update call waiting for the unpause within the function. Got 90% of it working. Just need to freeze the player at the X and Y position of when pause was hit. Nearly finished that too. Just hoped a quick pause true, pause false line had been in existence to detract from writing all the stops and starts at a manual level. Hint hint Rich! :D

Link to comment
Share on other sites

I make a pause loop that runs forever, It only checks if the unpause button is pressed. If you keep a loop going forever it won't update anything else. I am not familiar with Phaser's pause function but this is what I typically do.

function pause(){     while (1 === 1){          if (button === pressed){               exit();           }     }}
Link to comment
Share on other sites

That's a pretty good idea Kobaltic. Aint thought of it like that. I got it working with some maths and variables. Got a gamepaused = 0; if(gamepaused === 1) { //do some hacky physics pausing etc in here } then just use my usual update loop as gamepaused === 0 to reset and continue from there. Also got a destroy(); call on 2 buttons that effectively swap eachother but you would never know it when ingame. Total hack but works nonetheless haha :)

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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