Angular data in game

Hi,

How can I get data in Angular and pass it to PhaserGame. I need to get data for village, but don’t know how to do it. Here is my code for now:

export class MapsComponent implements OnInit {
    phaserGame: Phaser.Game;

    config: Phaser.Types.Core.GameConfig;
    constructor(private mapService: MapService) {
      console.log(this.mapService.getUserVillage());
      this.config = {
        type: Phaser.CANVAS,
        height: 600,
        width: 800,
        scene: [ MainScene ],
        parent: 'mapContainer',
        physics: {
          default: 'arcade',
          arcade: {
            gravity: { y: 100 }
          }
        }
      };
    }
    ngOnInit() {
      this.phaserGame = new Phaser.Game(this.config);
      //this.phaserGame.input.
    }
}

class MainScene extends Phaser.Scene {
    constructor(private mapService: MapService) {
      super({ key: 'main' });
      this.village = this.mapService.getUserVillage();
    }

    text: any;
    public village: Village;
}

I Found solution. I have to put data into local storage and then get it in MainScene.

  localStorage.setItem('village', 
  JSON.stringify(this.mapService.getUserVillage()));

class MainScene extends Phaser.Scene {

constructor() {

  super({ key: 'main' });

  this.village = JSON.parse(localStorage.getItem('village'));

}

}

1 Like