I'm trying to load an image to a canvas inside a function but when I start the code the image doesn't load but when the function is called again the image load. Can anyone tell me what's wrong?
const c = document.getElementById("myCanvas");
const ctx = c.getContext("2d");
const foodImg = new Image();
foodImg.src = "img/food.png";
start();
function start()
{
//code
ctx.drawImage(foodImg, xFood, yFood, size, size);
}