HTML 5 Canvas - Dynamically include multiple images in canvas
- by Ron
I need to include multiple images in a canvas. I want to load them dynamically via a for-loop.
I tried a lot but in the best case only the last image is displayed. I check this tread but I still get only the last image.
For explanation, here's my latest code(basically the one from the other post):
for (var i = 0; i <= max; i++)
{
thisWidth = 250;
thisHeight = 0;
imgSrc = "photo_"+i+".jpg";
letterImg = new Image();
letterImg.onload = function() {
context.drawImage(letterImg,thisWidth*i,thisHeight);
}
letterImg.src = imgSrc;
}
Any ideas?