I am currently trying to create a game in javascript and I wanted to use a jpg image I've drawn as a sprite and put it into a canvas, then further control the sprite to make it move left and right, but I can't seem to figure out how to let the image show in the canvas
I've searched up some similar questions such as this: How to add image to canvas The image I am adding is not from a browser but a downloaded image on the desktop of my computer.
I used the code in the above solution but it does not show the image
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
make_base();
function make_base()
{
base_image = new Image();
base_image.src = 'pic.jpg';
base_image.onload = function(){
context.drawImage(base_image, 0, 0);
}
}
I do not want the image to be a background but rather an image that can be used as a character(like a sprite in a game). Is there any other solutions to this problems or is there anything I'm doing wrong.