数组长度不断增加,运行越来越慢
function updateBalls(){ for(var i=0;i<balls.length;i++){ balls[i].x+=balls[i].vx; balls[i].y+=balls[i].vy; balls[i].vy+=balls[i].g; if(balls[i].y>=WINDOW_HEIGHT-RANIUS){ balls[i].y=WINDOW_HEIGHT-RANIUS; balls[i].vy=-balls[i].vy*0.75; } if(balls[i].x>WINDOW_WIDTH+RANIUS||balls[i].x<-RANIUS){ balls.splice(i,1); } // 从balls数组中移除跳出画布的小球 } console.log(balls.length); }