请叫我橙子蛋
2016-08-21 14:44
离开页面后,再回来会发现有很多小球都叠在一起了
性能优化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-RADIUS ){
balls[i].y = WINDOW_HEIGHT-RADIUS;
balls[i].vy = - balls[i].vy*0.75;
}
}
var cnt = 0
for( var i = 0 ; i < balls.length ; i ++ )
if( balls[i].x + RADIUS > 0 && balls[i].x -RADIUS < WINDOW_WIDTH )
balls[cnt++] = balls[i]
while( balls.length > Math.min(300,cnt) ){
balls.pop();
}
}
炫丽的倒计时效果Canvas绘图与动画基础
96746 学习 · 1000 问题
相似问题