Heppell08 Posted March 1, 2014 Share Posted March 1, 2014 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 More sharing options...
Magnifisite Posted March 1, 2014 Share Posted March 1, 2014 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 More sharing options...
Heppell08 Posted March 1, 2014 Author Share Posted March 1, 2014 Yeah i think thats going to be what i do. I'm going to create a paused bool and if true use that as a means to stop and start the game. Link to comment Share on other sites More sharing options...
Magnifisite Posted March 1, 2014 Share Posted March 1, 2014 You could just create your own pause boolean like you said and only call your update methods if !paused. (Not exactly sure if you meant the same thing but I guess you do ) Link to comment Share on other sites More sharing options...
Heppell08 Posted March 1, 2014 Author Share Posted March 1, 2014 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! Link to comment Share on other sites More sharing options...
Kobaltic Posted March 1, 2014 Share Posted March 1, 2014 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 More sharing options...
Heppell08 Posted March 2, 2014 Author Share Posted March 2, 2014 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 More sharing options...
Kobaltic Posted March 6, 2014 Share Posted March 6, 2014 Well sounds like you are on the right path for what you want. Link to comment Share on other sites More sharing options...
Recommended Posts