打字稿扩展关键字不起作用 [英] Typescript extends keyword not working

查看:91
本文介绍了打字稿扩展关键字不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Visual Studio,Phaser和Typescript开发第一款游戏.

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

这有效:

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);
}
}

这不是:

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?

推荐答案

phaser.js的脚本标签必须位于脚本的脚本标签上方.

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

每个脚本都按顺序运行,并且第二个示例在运行后立即依赖于已创建的Phaser对象.

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.

这篇关于打字稿扩展关键字不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆