对于画布的双缓冲,创建第二个画布元素并在其上绘制。之后使用drawImage()方法将图像绘制到第一个画布上。
// canvas element var canvas1 = document.getElementById('canvas'); var context1 = canvas1.getContext('2d'); // buffer canvas var canvas2 = document.createElement('canvas'); canvas2.width = 250; canvas2.height =250; var context2 = canvas2.getContext('2d'); // create on the canvas context2.beginPath(); context2.moveTo(10,10); context2.lineTo(10,30); context2.stroke(); //render the buffered canvas context1.drawImage(canvas2, 0, 0);
以上是HTML5 Canvas支持双缓冲吗?的详细内容。更多信息请关注PHP中文网其他相关文章!