Baptiste Posted March 27, 2015 Share Posted March 27, 2015 Hi everybody ! I'm creatin a little game (you can test the prototype here : http://www.baptistemenard.com/pixeltank/level.html) and I got a little problem : I can't resume when the game is paused, because obviously the game loop is stopped. I searched on the internet (maybe poorly and I'm sorry beforehand) but I didn't found cases like mine. Here is my pause sprite code :// Affiche les images de navigationUserInterface.prototype.drawNavigation = function() { // Pause this.pause = game.add.sprite(600, 12, 'pause'); this.pause.inputEnabled = true; this.pause.events.onInputDown.add(pauseOrResume, this); // Aide this.help = game.add.sprite(660, 12, 'help'); // Quitter this.exit = game.add.sprite(720, 12, 'exit');}... and the callback :function pauseOrResume(event, sprite) { // Pause if (!game.paused) { game.paused = true; // Bouton play userInterface.pause.loadTexture('resume'); } // Resume else { game.paused = false; // Bouton pause userInterface.pause.loadTexture('pause'); }}Thanks for help ! Link to comment Share on other sites More sharing options...
Rakzah Posted March 28, 2015 Share Posted March 28, 2015 I'm not very experienced as well, but I had a similar problem. If game.paused is set to true, update() won't run anymore, so InputDown won't be checked.There are 2 solutions: 1) Not sure if this will work, but you can try it: While paused, the game will run through pauseUpdate() - just implement it similar to the update() function, it will only run when the game is paused. You might try to check for onInputDown() there. 2) Don't use game.paused = false. I don't know if this is bad style, but it works for me. My update() function looks like this:if (!paused) { this.doThis(); this.doThat(); ...} else { this.pauseUpdate();}So just add a global variable "paused" which is set to "false" by default. Set it to "true" if your pauseOrResume() function. You can then decide which functions will still be run while your game is run and check for the InputDown event while pause is set to false. Hope I could help you! Link to comment Share on other sites More sharing options...
Recommended Posts