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?
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.