I'm making a game that utilizes an HTML canvas and draws images on it. 60 times every second it clears the screen and redraws all the elements to create animations. However, when I use images instead of just shapes, the images will be there, but will flash in and out and won't be visible all the time. I've made a game like this before(https://graphics-game.napoleon1027.repl.co/) and it was composed of entirely squares and circles and never had issues. Then when I added an image it began to flash in and out.
<!DOCTYPE html>
<html>
<body>
<canvas id="canvas" width="900" height="600" style="border:1px solid #d3d3d3;">
</canvas>
<script>
var xcoord = 50
var ycoord = 50
function drawscreen() {
var ctx = document.getElementById('canvas').getContext('2d');
void ctx.clearRect(0, 0, 900, 600);
image = new Image()
image.src = "https://upload.wikimedia.org/wikipedia/en/c/c8/Very_Black_screen.jpg"
void ctx.drawImage(image, 0, 0, 200, 200, xcoord, ycoord, 50, 50);
ycoord++
xcoord++
}
setInterval(drawscreen, 16);
</script>
</body>
</html>