eguneys Posted August 6, 2014 Share Posted August 6, 2014 I guess this is not a problem if you just reload a page, but mywebsite changes routes without reload. I have a Phaser game running on a page, when I visit another page, Inoticed game is still running. I never had to think about how todestroy the game properly since now. How do I destroy a Phaser game, what callbacks are fired and what elsedo I have to do, to properly destroy a Phaser game. Link to comment Share on other sites More sharing options...
Sebi Posted August 6, 2014 Share Posted August 6, 2014 You could as well load the game in an iframe, then you don't have to care about that anymore. Link to comment Share on other sites More sharing options...
Str1ngS Posted August 6, 2014 Share Posted August 6, 2014 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#destroyIt stops the timer and removes the internal shizzle so at least the game won't take any processing time anymore clark and Lypzis 1 1 Link to comment Share on other sites More sharing options...
freke1981SWE Posted August 6, 2014 Share Posted August 6, 2014 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 More sharing options...
eguneys Posted August 6, 2014 Author Share Posted August 6, 2014 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? tidelake 1 Link to comment Share on other sites More sharing options...
eguneys Posted August 6, 2014 Author Share Posted August 6, 2014 You could as well load the game in an iframe, then you don't have to care about that anymore.How do i load Phaser in an iframe properly? Link to comment Share on other sites More sharing options...
lewster32 Posted August 6, 2014 Share Posted August 6, 2014 How do i load Phaser in an iframe properly? Just put Phaser on a webpage as normal, then include that webpage in an iframe on another webpage via the iframe src parameter Link to comment Share on other sites More sharing options...
eguneys Posted August 6, 2014 Author Share Posted August 6, 2014 On a second thought i don't want an iframe i want to control the game within the current page. It would be ugly with iframe. Phaser guys should've thought of this damn. Link to comment Share on other sites More sharing options...
Sebi Posted August 6, 2014 Share Posted August 6, 2014 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 More sharing options...
eguneys Posted August 6, 2014 Author Share Posted August 6, 2014 Hey @Sebastian, My current interaction is to provide a fullscreen an a volume mixercontrol. For future I am thinking a leaderboard. I am not currentlysure but page interaction would be fun and should be needed. When user quits the game or visits another page, game should bedestroyed. Iframe is no different, what do you think about this? Why would the app run out of memory, if I destroy the game properlyand it's garbage collected isn't it? In this case i supposePhaser.Game.destroy is enough? Currently i don't destroy the game but simply refresh the page if userquits the game or leaves the page. Do you think that's a good approach? Link to comment Share on other sites More sharing options...
jjwallace Posted April 27, 2016 Share Posted April 27, 2016 On 8/6/2014 at 2:15 AM, SebastianNette said: You could as well load the game in an iframe, then you don't have to care about that anymore. I prefer throwing my computer into the bathtube to destroy my phaser game. Link to comment Share on other sites More sharing options...
umesh Posted October 7, 2017 Share Posted October 7, 2017 . 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 More sharing options...
nag0121 Posted September 17, 2018 Share Posted September 17, 2018 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 More sharing options...
Recommended Posts