To clear a canvas to transparency, you do this:
var ctx = canvas.getContext("2d");
ctx.clearRect(0,0, //Starting coordinates
canvas.width, canvas.height //Ending coordinates
);
But I'm writing a more complex abstract system. To avoid calling .getContext
all over the place, I have a pseudo-class to manage contexts of all layers. Every sub-program is then passed a ctx
variable without the canvas:
Something.prototype.renderMe = function(ctx) {
//draw Something
}
I occurred to need to clear all context area. Is that possible just with canvas context?
The context contains a property which refers to its canvas.
var myCanvas=ctx.canvas;
ctx.clearRect(0,0,myCanvas.width,myCanvas.height);
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다