Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在html5画布上绘图是';t绘画_Html_Html5 Canvas - Fatal编程技术网

在html5画布上绘图是';t绘画

在html5画布上绘图是';t绘画,html,html5-canvas,Html,Html5 Canvas,我在html5画布上绘制矩形时遇到问题。我正在调用此函数,但没有显示任何内容。我知道它的工作方式,因为我可以向它添加一个警报,它工作得很好。有什么想法吗?或者我只是傻了。如果您想查看完整的代码,项目位于 多谢各位 paintContainer: function(){//doesn't work var cont = this.container; this.context.fillStyle = cont.color; this.context.fillRect(con

我在html5画布上绘制矩形时遇到问题。我正在调用此函数,但没有显示任何内容。我知道它的工作方式,因为我可以向它添加一个警报,它工作得很好。有什么想法吗?或者我只是傻了。如果您想查看完整的代码,项目位于 多谢各位

paintContainer: function(){//doesn't work
    var cont = this.container;
    this.context.fillStyle = cont.color;
    this.context.fillRect(cont.x, cont.y, cont.width, cont.height);
}

paintContainer: function(){//works just fine
            alert('hi');
    var cont = this.container;
    this.context.fillStyle = cont.color;
    this.context.fillRect(cont.x, cont.y, cont.width, cont.height);
}

从您的网站引用代码,这是因为在您尝试绘制的填充已经绘制之后加载了背景。因此,如果您将代码更改为:

background.onload = function() {
    context.drawImage(background, 0, 0);
    drawTitle();        
}

var b = new Board(context);
而是在
onload
内绘制
板:

background.onload = function() {
    context.drawImage(background, 0, 0);
    drawTitle();    
    var b = new Board(context); 
}
你会得到你想要的效果。我建议您创建一个在
onload
方法中被调用的方法,该方法在资产加载后继续您的游戏