Jump to content

Pass custom variable into Phaser.Game()


brentstrandy
 Share

Recommended Posts

I'm trying to seed my game with custom data. For example, in Phaser 2 I was able to instantiate a new Game object with any number of parameters. It seems Phaser 3 is only looking for a config object with specific properties and nothing more. Is there a way to do this?

new Phaser.Game({
  type: Phaser.AUTO,
  width: 916,
  height: 400,
  scene: [BootScene, PreloaderScene, MenuScene, GameScene],
  antialias: true,
  myCustomObject: { }
});

Note the "myCustomObject" passed into the game.

I would prefer to keep my Phaser implementation to one line and not have to resort to the following:

var myGame = Phaser.Game(config);
myGame.scene.start('myScene', myCustomObject);

 

Link to comment
Share on other sites

  • 4 weeks later...

I think it would have to be 

{
  callbacks: {
    preBoot: function (game) {
      game.registry.merge(myCustomObject);
    }
  }
}

You could make a feature request. Maybe a game config key like data that could pass through arbitrary data.

Link to comment
Share on other sites

  • 1 year later...
 Share

  • Recently Browsing   0 members

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