I need to draw several images on various canvas, so I would like to do a generic function that would allow me to pass the arguments to draw the positioned images.
I thought of the following generic function:
var drawIt = new function(CanvasCtx,drawObj,x,y) {
this.CanvasCtx = CanvasCtx;
this.drawObj = drawObj;
this.x = x;
this.y = y;
this.drawObj.onload = function(){
this.CanvasCtx.drawImage(this.drawObj,this.x,this.y)
}
}
Then when I set the Canvas and the image:
var canvas = document.getElementById("mycanvas");
var ctx = canvas.getContext("2d");
var Image1 = new Image();
Image1.src = "https://www.google.com.br/images/srpr/logo11w.png";
I could define a function to start on body load:
function drawScreen(){
drawIt(ctx,Image1,100,100);
}
But I get the error that the onload property can not be assigned to an unidentified object.
Can anyone help me build this generic function?