JAVASCRIPT == 画线慢的问题,折磨我两个星期了!!!!
用 Canvas=DDraw.DrawSurface; 方法来动态写字,为什么每次都要把以前写过的字重新写一遍呢?
具体代码:
<!doctype html public "-//W3C//DTD XHTML 1.0 Transitional//EN "
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<body>
<script language= "VBScript ">
</script>
<script language= "JavaScript ">
var interval=null;
var loopFlag=0;
var loopIndex=0;
var arr=new Array();
//从文件中把坐标读到程序的数组里,文件里每一行有两个坐标x,y
function IPoint(){
this.x=0;
this.y=0;
}
var i_x=0;i_y=0;
var fso = new ActiveXObject( "Scripting.FileSystemObject ");
var f = fso.OpenTextFile( "C:/file/data1.txt ",1);
var iIndex = 0;
while(!f.AtEndOfStream) {
var s=f.ReadLine();
var arrLL=s.split(/,/);
var p=new IPoint();
i_x=arrLL[0];
i_y=arrLL[1];
p.x=i_x;
p.y=i_y;
arr[iIndex]=p;
iIndex++;
}
f.close();
//坐标以点的形式 画在DDraw里
function lBegin(){
//以前用setTimeout
interval=window.setInterval( 'drawLine ',50);
}
function drawLine(){
creatLine(loopFlag);
loopFlag++;
if(loopFlag > arr.length-2){
window.clearInterval(interval);
}
}
//坐标以点的形式 画在DDraw里
function creatLine(loopIndex){
var x0=arr[loopIndex].x;
var y0=arr[loopIndex].y;
var x1=arr[loopIndex + 1].x;
var y1=arr[loopIndex + 1].y;
var Canvas=DDraw.DrawSurface;
Canvas.Line(x0,y0,x1,y1);
DDraw.DrawSurface = Canvas; //每次都把以前画过得再生成一次,按道理应该只画本次循环生成的线
}
&n