小编fel*_*cha的帖子

打字稿画布

我正在学习打字稿,我对这门课有疑问,我现在的代码是

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);
    
} …
Run Code Online (Sandbox Code Playgroud)

html javascript dom canvas typescript

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

canvas ×1

dom ×1

html ×1

javascript ×1

typescript ×1