2013-04-13 140 views
0

下面的代码(我只是给了一段代码)根据时间动画几张图片。就像Flash动画,在某些时候图像开始在特定时间或帧数上移动。我的问题是,有没有更好的方法来做到这一点?我知道我可以使用setInterval以外的东西。我正在计算经过时间并根据时间间隔设置图像。多个动画像闪光灯

这是问题的ClassLoadImages.prototype.m_draw。

function doGameLoop() { 

    ctx.clearRect(0,0,600,400); 
    now = new Date(); 

    totalSeconds = (now - start)/1000; 
    last = now; 

    ctx.fillText("totalSeconds=" +totalSeconds ,10,100); 
    if (totalSeconds>2 && totalSeconds<6) 
    { 
     img2.m_draw(130); 
    } 
    if (totalSeconds>4 && totalSeconds<8) 
    { 
     img3.m_draw2(230); 
    } 

    if (totalSeconds>10){ 
     start = new Date();//start again 

    } 
    img.m_draw(30); 
    // fi++; 
} 



var img= new ClassLoadImages(30,30); 
var img2= new ClassLoadImages(30,30); 
var img3= new ClassLoadImages(30,30); 
</script> 
+0

你在画布上试过css3动画吗? –

回答