Jump to content

What's the proper way to destroy a Phaser 3 game instance?


Doug
 Share

Recommended Posts

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

 

DestroyMethod.JPG

Link to comment
Share on other sites

  • 5 months later...

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

 Share

  • Recently Browsing   0 members

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