1
JavaScript远非我的优势之一;因此,如果我的问题似乎对你们许多人来说是非常补救的道歉。通过Javascript和HTML5更新背景图片Canvas
我试图通过Javascript和HTML5 Canvas实现Boids。虽然植绒行为已经确立,但应用程序看起来相当简单,只是空白的背景。
由于这个原因,我试图使用一个图像作为我的背景,但我有困难。
this.draw = function() {
/* First clear everything */
this.context.clearRect(0, 0, this.canvas.width, this.canvas.height);
/* And ink them */
this.context.strokeStyle = "#000";
this.context.stroke();
/* Draw each boid */
for(var i in this.boids) {
this.boids[i].draw(this.context, this.size);
}
}
如果任何人有如何将上述功能内绘制背景图像的知识,请你能告诉我:)
你能告诉我们一些周围的代码吗?什么对象是“这个”? – Bergi 2012-04-27 12:39:20
“this”与控制演示文稿的Arena对象有关。它在HTML中被调用: var canvasElement = document.getElementById(“boids”); arena = new Arena(canvasElement,8,8); – 2012-04-27 12:42:31