javascript - create jumping effect for an object -
here created grass object , has 2 methods jump , fall.it jumps when user presses key on keyboard.it jumps ,its alright.but want fall previous position.. i have created keypressed variable value either true of false.it determine boundary how high object can jump. the object should fall previous position after each jump.which can't manage do.. also jump not realistic enough ...how problems can solved jsfiddle link image full code: <html> <body> <canvas id="mycanvas"></canvas> <script> var canvas=document.getelementbyid("mycanvas"); var ctx=canvas.getcontext('2d'); canvas.width=500; canvas.height=500; canvas.style.border="1px solid black"; var keypressed=true; var img=new image(); img.src="grass.jpg"; function grass(x,y){ this.x=x; this.y=y; this.image=img; } grass.prototype.draw=function(){ ctx.drawimage(this.image,this.x,this.y); } grass.prototype.hop=function(){ this.y-...