I've been writing some examples with RequestAnimationFrame and Canvas:
var ctx; var x=0,y=0,v_x=5,v_y=5; window.addEventListener('load',init); window.requestAnimationFrame = (function(){ return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || function(f){ window.setTimeout(f,1000/60); } })(); function init(){ ctx = document.getElementById("canvas").getContext("2d"); draw(); } function draw(){ ctx.beginPath(); ctx.rect(0,0,50,50); ctx.closePath(); ctx.fill(); x += v_x; y += v_y; requestAnimationFrame(draw); } The problem is that I want the Rect() to go diagonally down with the variables v_x and v_y and the requestAnimationFrame, then I get the Rectangle fully drawn, but it doesn't move!