Jump to content

rmbennin
 Share

Recommended Posts

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

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

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

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.

Link to comment
Share on other sites

  • 1 year later...

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

  • 6 months later...
 Share

  • Recently Browsing   0 members

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