I'm trying to call an image(redraw) whenever I move my mouse, but the problem is image sometimes inconsistently flickers when moving mouse and this is really annoying.
I tried to find answers from other Stack Overflow posts but they are not quite similar to mine.
I simplified my code so its easy to understand.
The thing is I have to call an image whenever mouse is moved so it works with other codes I wrote.
The reason that I wrote code this way is that so img.src can be changed whenever user clicks certain position on the page.
Going into further details it basically passes object with image path that changes img.src when user clicks.
The webpage is constantly changing so the mousemove is necessary.
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
canvas.onmousemove = mousemove;
function mousemove(e){
ctx.clearRect(0,0,canvas.width,canvas.height);
var img = new Image(); // Create new img element
img.addEventListener("load", function() {
ctx.drawImage(img,100,100,400,400);
}, false);
img.src = 'images/reception.jpg';
}