Phaser.io 3: Get game size in scene
The following should work:
scene.sys.game.scale.gameSize
You can use the default camera:
ship.setPosition(this.cameras.main.centerX, this.cameras.main.centerY);
From the Phaser 3 API Documentation on Camera
:
Cameras, by default, are created the same size as your game, but their position and size can be set to anything.
In a scene, in the preload()
and create()
methods (not in the constructor) you can access the canvas element with this.sys.game.canvas
. So to get the canvas size, you can do:
create() {
let { width, height } = this.sys.game.canvas;
}
For my part I like to add the following code to ease the access to the canvas:
preload() {
this.canvas = this.sys.game.canvas;
}