Typescript extends keyword not working

2019-09-11 00:24发布

I'm developing my first game using Visual Studio, Phaser and Typescript.

I can't get my classes to work when I use the extends key word

This works:

class Game  {

game: Phaser.Game;

constructor() {
    // init game
    this.game = new Phaser.Game(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}

This does not:

class Game extends Phaser.Game{

constructor() {
    // init game

    super(window.innerWidth * window.devicePixelRatio - 20, window.innerHeight * window.devicePixelRatio - 20, Phaser.CANVAS, 'content', State);
}
}

I've been trying to figure this out all day without success, can anybody shed some light on it?

1条回答
迷人小祖宗
2楼-- · 2019-09-11 01:08

The script tag for phaser.js needs to be above the script tag for your script.

Each script runs in order and your second example has an immediate dependency on the Phaser object already being created as soon as it runs.

查看更多
登录 后发表回答