this function take the canvas and draw on it 2 images side by side on it sometimes it up to 4 images but when i call context.clearRect(0, 0, canvas.width, canvas.height);
it make the canvas flashes for a little bit even thought the images should appear more continuous is there any other way to do that using canvas
PS: the 2 images on the left/right background is transparent so when i can't just draw image over other
function drawimagesonCanvas(canvas, url1, diac1, url2, diac2) {
var IsBoth = (url2 != null);
var context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
let loadImage = (url, diac, x, y, w, h, f) => new Promise((resolve, reject) => {
var img = new Image();
img.addEventListener('load', () => {
if (f) {
context.save();
context.scale(-1, 1);
context.drawImage(img, x, y, -w, h);
context.restore();
}
else {
context.drawImage(img, x, y, w, h);
}
resolve();
});
img.src = url;
});
return loadImage(api + Jism, null, 50, 0, 350, 500).then(() => {
if (IsBoth) {
return Promise.all([
loadImage(api + url1, null, 50, 0, 350, 500),
diac1 != null ? (loadImage(api + diac1, null, 80, 120,80, 80)) : 1,
loadImage(api + url2, null, -50, 0, 350, 500, true),
diac2 != null ? (loadImage(api + diac2, null, -350 + 80, 120, 80, 80, true)) : 1,
]);
} else {
return Promise.all([
loadImage(api + url1, null, 50, 0, 350, 500)
]);
}
})
}