Im writing this code but i don’t know why the pattern is wrong. Thank’s.
var mycanvas = myfunc();
function myfunc(){
this.canvas = document.createElement('canvas');
this.canvas.setAttribute("ID","mycanvas");
this.canvas.width = "500";
this.canvas.height = "500";
this.img = new Image();
this.img.src = 'img-gioco/gattino.png';
this.ctx = this.canvas.getContext('2d');
this.img.addEventListener("load",myDraw);
document.body.appendChild(this.canvas);
}
function myDraw(){
var tileX = 0;
var tileY = 0;
var w = 100;
var h = 100;
var myarray = [];
for(var i=0; i<5; i++){
myarray.push(tileX);
myarray.push(tileY);
tileX += w;
tileY = 0;
}
for(var i=0; i<myarray.length; i++){
ctx.drawImage(img,myarray[i],myarray[i+1]);
console.log(myarray[i]);
}
}