繁体   English   中英

html5 canvas object图纸

[英]html5 canvas object drawing

我在 canvas 很新,但我试图画一个下降的 object。 首先我试图只画一个 object,但它不起作用。 我怎么能画一个 object (如果你可以这么好,但没有必要让我知道如何让它移动)? 或者我在这里做错了什么? 代码:

let c, ctx;

window.onload = function(){
    
    c = document.getElementById("boom");
    ctx = c.getContext("2d");
    c.width = window.innerwidth;
    c.height = window.innerHeight;

    setup();
    draw();
};

function draw(){
    //window.requestAnimationFrame(draw);
    ctx.fillStyle = "rgba(0,0,0,1)";
    ctx.fillRect(0, 0, c.width, c.height);
    ctx.fillStyle = "red";
    ctx.fillRect(100, 100, 100, 100);
    regen.push(new regen(this.x, this.y, this.w, this.h, this.color));
};

function setup(){

}

function regen(x, y, w, h, color){
    this.x = 100;
    this.y = 100;
    this.width = 20;
    this.height = 40;
    this.color = "blue";
    //this.xSpeed = 4;
    //this.ySpeed = 4;

    this.draw = function(){

        //this.update = function(){
            //this.x += this.xSpeed;
            //this.y += this.ySpeed; 
        //}
    }
}



function getRndFloat(min, max) {
    return Math.random() * (max - min + 1) + min;
}

你在innerwidth有错字:它必须是innerWidth 但是你没有定义,你的 canvas 没有宽度

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM