rmbennin Posted November 3, 2013 Share Posted November 3, 2013 Hello all, I am trying to basically stop my Phaser game completely, the main thing is getting it to stop "updating". I'm not sure how to do this. This is my code creating the game:game = new Phaser.Game(1000, 600, Phaser.AUTO, "gameCanv", { preload: preload, create: create, update: update, quitGame: quitGame } ); In the quitGame function, I am trying to stop the game from running, so I can see if the user got a high score, update the scoreboard for it, and ask the user if they want to play again with different conditions. I have this code for that function: function quitGame(){ console.log("in quitGame"); ingredient.kill(); chef.kill(); score = 0; gameOverOne();} //end quitGame function Please help... Thank you! Link to comment Share on other sites More sharing options...
rich Posted November 3, 2013 Share Posted November 3, 2013 game.destroy() will kill the update loop and all the various listeners. Link to comment Share on other sites More sharing options...
rmbennin Posted November 3, 2013 Author Share Posted November 3, 2013 game.destroy() will kill the update loop and all the various listeners. I thought that would work too (which it did, besides the fact my sprites won't die (I have kill on both) for some reason, but then I got these two errors: Uncaught TypeError: Cannot call method 'postUpdate' of null Uncaught TypeError: Cannot read property 'disabled' of null Any ideas on what the problem is? Sorry to be a bother! Link to comment Share on other sites More sharing options...
rich Posted November 3, 2013 Share Posted November 3, 2013 If you want to destroy a sprite you should call sprite.destroy() on it, kill() is just for object pooling. However are you sure you want to actually destroy the whole game? I only ask because you say you just want to present them with a highscore and the option to play again - to me this just sounds like changing to a "Game Over" state and then potentially jumping back to the game start again. game.destroy() is like a final kill-switch, there's no coming back from it without reloading the page itself really. Link to comment Share on other sites More sharing options...
beeglebug Posted November 3, 2013 Share Posted November 3, 2013 Rich: I've just looked into the issue he reported about the errors after calling game.destroy(), and there is definitely something wrong. I've solved one of the errors, to do with the input event listeners not being removed correctly when input.stop is called (pull request #166), but the other issue is a bit more complex. It looks like the call to cancelAnimationFrame is doing nothing, according to the docs, it needs to be passed the ID returned by requestAnimationFrame, but I tried that to no avail. I think the easiest solution is to add a "destroyed" flag to the game, and bail out of the updateRAF function if it is set, but I thought i'd leave you to make that call, as it may come with a performance hit. rmbennin 1 Link to comment Share on other sites More sharing options...
Clemzd Posted December 19, 2014 Share Posted December 19, 2014 Hi everyone, I have quite the same need, I want to pause the game but not to destroy the game.I want to do that because otherwise there is a still process running and it consumes CPU.By looking at the code, I found that "game.gamePaused()" pause the game but I think I shouldn't use that function.Is it correct to use "game.gamePaused()" to pause the game? Link to comment Share on other sites More sharing options...
jagged0815 Posted July 2, 2015 Share Posted July 2, 2015 you can use game.lockRender = true; its documented under: http://phaser.io/docs/Game.js.html/Phaser.Game.html Nestor 1 Link to comment Share on other sites More sharing options...
Recommended Posts