Jump to content

How to destroy Phaser game properly


eguneys
 Share

Recommended Posts

I guess this is not a problem if you just reload a page, but my

website changes routes without reload.

 

I have a Phaser game running on a page, when I visit another page, I

noticed game is still running. I never had to think about how to

destroy the game properly since now.

 

How do I destroy a Phaser game, what callbacks are fired and what else

do I have to do, to properly destroy a Phaser game.

 

Link to comment
Share on other sites

You could as well load the game in an iframe, then you don't have to care about that anymore.

 

Don't do stuff like that. It always a good idea to clean up behind yourself.

@OP you can call Game.destroy()

http://docs.phaser.io/Phaser.Game.html#destroy

It stops the timer and removes the internal shizzle so at least the game won't take any processing time anymore

 

Link to comment
Share on other sites

I recently included a phaser game in an angular app, phaser adds some global event listeners on document and window, they are not removed when you run just destroy on the game. I got rid of them by editing the phaser source due to the event listeners are added as anonymous functions. By doing this I can change the route with no console errors.

Link to comment
Share on other sites

Don't do stuff like that. It always a good idea to clean up behind yourself.

@OP you can call Game.destroy()

http://docs.phaser.io/Phaser.Game.html#destroy

It stops the timer and removes the internal shizzle so at least the game won't take any processing time anymore

Loading a game in an iframe is not really bad. It's the same way a flash game is loaded via an object tag. An object-tag is just behaving like an iframe.

I still believe that this would be the cleanest way. However, the threadstarter discarded this option.

@eguneys

In what way are the games on your app interacting with the page?

Are you going to unload all of the games logic everytime the user leaves the game?

Single page apps can run out of memory pretty fast.

Link to comment
Share on other sites

Hey @Sebastian,

 

My current interaction is to provide a fullscreen an a volume mixer

control. For future I am thinking a leaderboard. I am not currently

sure but page interaction would be fun and should be needed.

 

When user quits the game or visits another page, game should be

destroyed. Iframe is no different, what do you think about this?

 

Why would the app run out of memory, if I destroy the game properly

and it's garbage collected isn't it? In this case i suppose

Phaser.Game.destroy is enough?

 

Currently i don't destroy the game but simply refresh the page if user

quits the game or leaves the page. Do you think that's a good approach?

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...

 .     you can use destroy() method at any level if you will use it at that level which level you want to remove.

so , if you will use it at the main object level so canvas will be removed from page.

EX-

var game = new Phaser.Game(phaserConfig.w, phaserConfig.h, Phaser[phaserConfig.mode], "NL");
 
game.destroy();

 

Link to comment
Share on other sites

  • 11 months later...
On 8/6/2014 at 3:40 PM, eguneys said:

Yes Game.destroy() stops the game but it doesn't remove the canvas from the screen. Do i have to manually remove it? Also i am wondering is that it?

 

What about shutdown method for States, what do i have to call there? For example calling all audio to stop is an idea. What else?

have you got rid of this issue? if you are pls lemme know. I am facing the same problem.

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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