I'm new with canvas. I'm a student currently developing a Runner Game in canvas. I have the function jump()
, that is called when the mousedown()
event occurs;
function jump(){
img= new Image();
//is_jump=1;
h.clearRect(20,430,170,250);
img.onload= function(){
//h.drawImage(img,mx,my,190,280,120,410,190,350);
h.drawImage(img,mx,my,190,350);
//mX--;
//mY--;
}
img.src= "mario-Copy.png";
h.clearRect(mx,my,190,350);
//for(i=mx;i<130;i+=7)
//{
if(mx<110&&my<480){
mx=(mx+5);
my=(my-15);
//setTimeout(h.drawImage(img,mx,my,190,350),100000/5);
h.drawImage(img,mx,my,190,350);
}else{
mx=60;
my=410;
}
}
The problem is that the jumping character is not working properly, it jumps slowly and not clear the previous jumping state image while moving on.
So help me out so my animation works properly and smoothly.
The goal is to make the character jump by click.