Jump to content

Scene Manager returns null or undefined values


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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...