I'm wondering what is wrong with my code (why is the animation so jerky):
<html>
<head>
</head>
<body style="background:black;margin:0;padding:0;">
<canvas id="canvas" style="background:white;width:100%;height:100%;"/>
<script>
var img=new Image();
img.onload=function(){
var c=document.getElementById('canvas');
var ctx = c.getContext('2d');
var left,top;
left=top=0;
ctx.drawImage(img,left,top,20,20);
var f=function(){
left+=1;
top+=1;
c.width=c.width;
ctx.drawImage(img,left,top,20,20);
};
setInterval(f,20);
};
img.src="http://a.wearehugh.com/dih5/aoc-h.png";
</script>
</body>
</html>
From what I know canvas is supposed to be good at doing these kinda stuff? But if instead I used an element and manipulate its left and top it ended up being faster (less jerky)..
Is there something wrong with my script? or is this the best canvas can do?