balls[cnt++] = balls[i]这个技巧有其他方式代替吗?
ruti
ruti
2017-09-22
function updateBalls () { for (let 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 - RADIUS) { balls[i].y = WINDOW_HEIGHT - RADIUS; balls[i].vy = -balls[i].vy * 0.75; } /*小球已经出了左边界或者右边界,将小球删掉,防止占用内存*/ if(balls[i].x + RADIUS <= 0 || balls[i].x - RADIUS >= WINDOW_WIDTH) { balls.splice(i, 1); } } }
举报