Doug Posted August 25, 2017 Share Posted August 25, 2017 Hi I'm new to Phaser, so please forgive that I also posted to the Google Group on this subject. I'm not yet sure where it's best to ask this kind of question. I am developing a SPA with Angular2 and so am playing with Phaser 3 as it's modularity seems to enable it to be used with Angular2. I need to be able to load a game, then close it, then load a new game in it's place. What is the proper way to "destroy" a Phaser 3 game please? I note that there is a destroy method in src/scene/System.js as per the attached image. I notice the "TO DO" so it may be that this is just not implemented yet? Any thoughts or feedback would be very welcome. Thanks so much! Dougi Link to comment Share on other sites More sharing options...
rich Posted September 1, 2017 Share Posted September 1, 2017 Hi, There is a lot of work still left to do on destroying a Game instance, so for now, I'd avoid doing so! Link to comment Share on other sites More sharing options...
Doug Posted September 2, 2017 Author Share Posted September 2, 2017 Hi Rich Thanks so much for getting back to me and for this advice. Much appreciated and thank you for all your hard work! Dougi Link to comment Share on other sites More sharing options...
Doug Posted February 7, 2018 Author Share Posted February 7, 2018 Hi. I was wondering if there is any update on whether destroying a Game instance is possible yet, now that you're near release please? Thanks so much Link to comment Share on other sites More sharing options...
rich Posted February 7, 2018 Share Posted February 7, 2018 Yes, this works fine now. There is a test in the examples repo that destroys and creates a game 100 times. Link to comment Share on other sites More sharing options...
Doug Posted February 7, 2018 Author Share Posted February 7, 2018 SUPER thank you. I'll check that out. So excited about this release. Thanks so much! Link to comment Share on other sites More sharing options...
Doug Posted February 8, 2018 Author Share Posted February 8, 2018 Hi. I am working in Angular4. I have the following testing code, which I have adapted to include the destroy call. Html: <div id="phaser-example"></div> <button (click)="MoveCarrot()">Move Carrot</button> Typescript: import { Component } from '@angular/core'; import Phaser from 'phaser'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { phaserGame: Phaser.Game; carrot: any; config = { type: Phaser.CANVAS, parent: 'phaser-example', scene: { preload: function(){ this.load.image('carrot', 'assets/carrot.png'); }, create: function(){ this.carrot = this.add.sprite(400, 300, 'carrot'); this.input.on('pointerdown', function () { console.log("pointer clicked"); this.sys.game.destroy(true); }, this); } } }; constructor() { this.phaserGame = new Phaser.Game(this.config); console.log(this.phaserGame); } MoveCarrot() : void{ this.phaserGame.scene.scenes[0].carrot.x += 10; } } From the example at http://labs.phaser.io/view.html?src=src\game config\game destroy.js I would expect the game to be destroyed on mouse click. I see the "pointer clicked" console log, but the game isn't destroyed and there is no error message. Am I missing something please? Thank you so much D Link to comment Share on other sites More sharing options...
BlueLemming Posted February 11, 2018 Share Posted February 11, 2018 I think the game.destroy() function is still a dummy function in Phaser 3 beta 20. So, in other words, you could either make a build from the Phaser 3 source or just wait till the next release which should be tomorrow. Link to comment Share on other sites More sharing options...
Doug Posted February 12, 2018 Author Share Posted February 12, 2018 Ooooo, ok thank you. Will do. Very exited about this release! Link to comment Share on other sites More sharing options...
Doug Posted February 15, 2018 Author Share Posted February 15, 2018 Just to say that destroy is now working in Phaser 3 official release as follows: this.phaserGame.destroy(true); Thanks very much! This is going to be awesome. Teaching my kids phaser at the moment too! PutUOnTheMap, shortland and Elijah 1 2 Link to comment Share on other sites More sharing options...
Recommended Posts