Nonexistant world!

Total newbie (to Parser) here, so please be patient :slight_smile:

OK, so , even if official tutorials for phaser https://phaser.io/tutorials/how-to-use-phaser-with-typescript you see a code mentioning this.game.world… (at the bottom of the page) however, no such variable is available in the game’s scope.

  1. Is this something that has been now deprecated?
  2. if so, what’s the preffered way to get the stage/canvas dimensions?

I’m using Typescript, btw

This tutorial is for Phaser 2 CE, Phaser 3 works well with TypeScript, to start a fresh game you just need to put that:

import 'phaser';

const GameCfg: GameConfig = {
    type: Phaser.AUTO,
    parent: 'content',
    width: 640,
    height: 480,
    resolution: 1,
    backgroundColor: "#EDEEC9",
    plugins: {
        global: [],
        scene: []
    },
    scene: []
};

new Phaser.Game(GameCfg);

parent is the targeted DOM element in your HTML file :wink:

Thank you Gecko, I know how to create a simple game instance, my question was more about if we don’t use world variable in Phaser 3 what would be the best way to obtain dimensions of the stage…

For example one can use :

    let hei  = this.sys.game.config.height;
    let hei2 = this.game.config.height;

to get the height, but I’m not sure what’s the difference between those 2 approaches, or if it’s the best one…

Hi @SlavomirDurej, as version 3.16.2, the best way to get the size of the game canvas is this.scale.gameSize.width and this.scale.gameSize.height being this a reference to your scene. The ScaleManager is now in charge of that. See https://photonstorm.github.io/phaser3-docs/Phaser.Scale.ScaleManager.html

The world variable still exist but when you use Physics and is accesible from this.physics.world. It references the World instance in charge of handling the collisions and overlaps of all bodies in it. See https://photonstorm.github.io/phaser3-docs/Phaser.Physics.Arcade.World.html

1 Like