キャンバスと JavaScript を使い始めたばかりで、このスニペットの setTimeout が機能しない理由がわかりません。ループ内に含まれているため、最初は各フレームをトリガーすると思っていました。アニメーション機能内でも移動しようとしましたが、役に立ちませんでした。
$(document).ready(function(){
var canvas = $('#myCanvas');
var context = canvas.get(0).getContext('2d');
var Shape = function(x1,y1,x2,y2){
this.x1 = x1
this.y1 = y1
this.x2 = x2
this.y2 = y2
}
var shapes = new Array();
shapes.push(new Shape(0,0,50,50));
shapes.push(new Shape(50,50,50,50));
shapes.push(new Shape(0,100,50,50));
shapes.push(new Shape(50,150,50,50));
shapes.push(new Shape(0,200,50,50));
function animate(){
for (i=0;i<shapes.length;i++){
context.clearRect(0,0,500,500);
context.fillRect(shapes[i].x1,shapes[i].y1,shapes[i].x2,shapes[i].y2);
setTimeout(animate, 500);
};
};
animate();
});