課程
/前端開發(fā)
/Html5
/炫麗的倒計時效果Canvas繪圖與動畫基礎(chǔ)
離開頁面后,再回來會發(fā)現(xiàn)有很多小球都疊在一起了
2016-08-21
源自:炫麗的倒計時效果Canvas繪圖與動畫基礎(chǔ) 5-2
正在回答
性能優(yōu)化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();??? }}
請叫我橙子蛋 提問者
請叫我橙子蛋 提問者 回復(fù) 請叫我橙子蛋 提問者
舉報
學(xué)習(xí)HTML5中最激動人心的技術(shù)Canvas,徹底釋放自己的創(chuàng)造力
1 回答小球重疊問題?請?zhí)峁┮粋€思路
1 回答小球重復(fù)問題
5 回答小球出界問題
3 回答小球累加問題
2 回答小球彈起問題
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-08-25
性能優(yōu)化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();
??? }
}