Jump to content

Scene Manager returns null or undefined values


YakusActual
 Share

Recommended Posts

Hello all!

I am new to developing games for the web, and this forum, even though I found some topics helpful before I joined.

I have made a game using Phaser3 Framework, and everything works fine, except when I am trying to access the current scene to be able to exchange data from it with AngularJS directive wrapped around the game.

I have written a directive in Angular to host the code of the game:

app.directive('phaserGame', function() {
  return {
    restrict: 'E',
    scope: false,
    replace: true,
    transclude: false,
    controller: function($scope) {
      // This is the config object
      // 'parent' property defines the div id into which the game is to be injected
      $scope.config = {
        width: 800,
        height: 450,
        backgroundColor: '#36A9E1',
        scene: [MainScene, ArenaScene],
        parent: 'gameDiv'
      }

      // This is the most important line
      // This object creates the canvas and runs the game.
      $scope.game = new Phaser.Game($scope.config);

      //console.log($scope.game.scene);
      var arenaScene = $scope.game.scene;
      console.log(arenaScene)
    }
  }
});

The last two lines of the directive display an object of the scene manager inside the console as follows: https://imgur.com/a/B9ONp0N

If I try to retrieve any of the two scenes through that object, using: var arenaScene = $scope.game.scene.getAt(1); I get an undefined value.

Note: I have tried the same without angularJS to no avail.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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