在html5画布上绘图是';t绘画
我在html5画布上绘制矩形时遇到问题。我正在调用此函数,但没有显示任何内容。我知道它的工作方式,因为我可以向它添加一个警报,它工作得很好。有什么想法吗?或者我只是傻了。如果您想查看完整的代码,项目位于 多谢各位在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
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
方法中被调用的方法,该方法在资产加载后继续您的游戏