Jump to content
This forum will be closing down. Please move to the respective dedicated project forums.

Setting game size in Game constructor


cloakedninjas
 Share

Recommended Posts

Typescript says you the first call of constructor() should be super() so this isn't possible:

 

constructor() {	var devicePixelRatio = Math.min(Math.round(window.devicePixelRatio), 3) || 1;		super({		renderer: Phaser.AUTO,		width: window.innerWidth * devicePixelRatio,		height: window.innerHeight * devicePixelRatio	});}

But then doing this gets the error: Cannot read property 'setGameSize' of null

constructor(gameVars:any) {	super({	    renderer: Phaser.AUTO,	    parent: 'canvasContainer'	});    var devicePixelRatio = Math.min(Math.round(window.devicePixelRatio), 3) || 1;    this.scale.setGameSize(window.innerWidth * devicePixelRatio, window.innerHeight  * devicePixelRatio);}

When does the ScaleManager come into existence?

Link to comment
Share on other sites

In writing this post I figured it out, so rather than scrap this, I thought I'd post the solution - perhaps it can help someone in the future:

 

The ScaleManager gets initialised in the boot() method, so you can do the following:

boot() {    super.boot();    this.scale.setGameSize(window.innerWidth * this.devicePixelRatio, window.innerHeight  * this.devicePixelRatio);}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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