【发布时间】:2017-04-27 09:05:48
【问题描述】:
我正在学习打字稿,这门课有问题,我现在的代码是这样的
export class Window {
public title: string;
public width: number;
public height: number;
public canvas;
public ctx;
public constructor(title: string, width: number, height: number) {
this.title = title;
this.width = width;
this.height = height;
this.createCanvas();
}
public createCanvas(): void {
this.canvas = <HTMLCanvasElement>document.createElement('canvas');
this.ctx = this.canvas.getContext("2d");
this.canvas.width = 500;
this.canvas.height = 500;
document.body.appendChild(this.canvas);
}
export class Game {
private title: string;
private width: number;
private height: number;
public constructor() {
}
window: Window = new Window("titi", 100, 100);
}
画布不是这样创建的,屏幕上什么也没有出现,谁能帮忙?
【问题讨论】:
-
您是否在某处创建了
Game类的实例? -
我猜你是在干扰全局 Window 构造函数。
-
我没有创建 Game 的实例,现在我只有这两个这样的类
标签: javascript html typescript dom canvas