90 var img=new Image(); img.src="laptopmee.png"; img.onload=start; function start(){ requestAnimationFrame(animate); } function animate(time){ ctx.clearRect(0,0,cw,ch); ctx.drawImage(img,x,y); x += speedX * direction; if(x<minX){ x=minX; direction*=-1; } if(x>maxX){ x=maxX; direction*=-1; } requestAnimationFrame(animate); } }); </script> </html> Referensi : Learning HTML5 Canvas (modifikasi)
RkJQdWJsaXNoZXIy MTM3NDc5MQ==