Below are my three functions. I am calling function 1 & 2 in 3 but I am getting an error. My text is not showing inside my canvas. Only the image is getting displayed. How can I make the functions delay the text function until make_base
finishes loading.
Function 1
function make_base(img) {
base_image = new Image();
base_image.src = img;
base_image.onload = function(){
context.drawImage(base_image, 0, 0);
}
}
Function 2
function text(text) {
context.fillText(text, 50, 50)
}
Function 3
function render() {
make_base(xxx)
text(xxx)
}
I have used setTimeout doesnt work because sometimes make_base takes little time to load.